Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #27397 > unrolled thread

split string to array of float is different in JavaScript and jQuerry

Started byPatrick Chung <pchung705@gmail.com>
First post2015-04-22 05:18 -0700
Last post2015-04-22 14:46 +0200
Articles 2 — 2 participants

Back to article view | Back to comp.lang.javascript


Contents

  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

#27397 — split string to array of float is different in JavaScript and jQuerry

FromPatrick Chung <pchung705@gmail.com>
Date2015-04-22 05:18 -0700
Subjectsplit 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]


#27399

From"Christoph M. Becker" <cmbecker69@arcor.de>
Date2015-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