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


Groups > comp.lang.javascript > #27399

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

From "Christoph M. Becker" <cmbecker69@arcor.de>
Newsgroups comp.lang.javascript
Subject Re: split string to array of float is different in JavaScript and jQuerry
Date 2015-04-22 14:46 +0200
Organization solani.org
Message-ID <mh857r$67c$1@solani.org> (permalink)
References <13e97315-5fb8-41aa-a8bf-c162e8bbd1b3@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

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

csiph-web