Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.javascript
split string to array of float is different in JavaScript and jQuerry
Patrick Chung
4/22/2015 12:18:00 PM
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-...
1 Answer
Christoph M. Becker
4/22/2015 12:47:00 PM
0
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-...
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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
split string to array of float is different in JavaScript and jQuerry
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password