Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27397 > unrolled thread
| Started by | Patrick Chung <pchung705@gmail.com> |
|---|---|
| First post | 2015-04-22 05:18 -0700 |
| Last post | 2015-04-22 14:46 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
split string to array of float is different in JavaScript and jQuerry Patrick Chung <pchung705@gmail.com> - 2015-04-22 05:18 -0700
Re: split string to array of float is different in JavaScript and jQuerry "Christoph M. Becker" <cmbecker69@arcor.de> - 2015-04-22 14:46 +0200
| From | Patrick Chung <pchung705@gmail.com> |
|---|---|
| Date | 2015-04-22 05:18 -0700 |
| Subject | split string to array of float is different in JavaScript and jQuerry |
| Message-ID | <13e97315-5fb8-41aa-a8bf-c162e8bbd1b3@googlegroups.com> |
Sometimes it is practical to store array of numbers into string, and to separate values by comma for example. To collect this data from text box in our form, we use different code in JavaScript and jQuery. Read more: http://www.cirvirlab.com/index.php/jquery-code-examples/185-jquery-javascript-split-string-to-array-of-float.html
[toc] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2015-04-22 14:46 +0200 |
| Message-ID | <mh857r$67c$1@solani.org> |
| In reply to | #27397 |
Patrick Chung wrote:
> Sometimes it is practical to store array of numbers into string, and to separate values by comma for example. To collect this data from text box in our form, we use different code in JavaScript and jQuery.
>
> Read more:
>
> http://www.cirvirlab.com/index.php/jquery-code-examples/185-jquery-javascript-split-string-to-array-of-float.html
Consider using $.map instead of $.each:
var cosPoints = $('#textfield1').val().split(',');
var arrayPoints = $.map(cosPoints, function (str) {
return parseFloat(str);
});
Or, using plain ES 5.1:
var arrayPoints = cosPoints.map(function (str) {
return parseFloat(str);
});
--
Christoph M. Becker
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web