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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
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 Wed, 22 Apr 2015 14:46:58 +0200
Organization solani.org
Lines 23
Message-ID <mh857r$67c$1@solani.org> (permalink)
References <13e97315-5fb8-41aa-a8bf-c162e8bbd1b3@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-Trace solani.org 1429706811 6380 eJwNyMERACEIA8CW5EgCVw6K9l+C/naWLtMKiAIPT1bsD+MRw/TCo8KbWCyWee5JTu+k2P3nBQ3REK4= (22 Apr 2015 12:46:51 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Wed, 22 Apr 2015 12:46:51 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
X-User-ID eJwFwYEBwCAIA7CbkLa4c9DR/08wYSp0C6JA06cEbbPQNmZhaddG0jmnr6JFrPnGZOuPBxLUEOk=
In-Reply-To <13e97315-5fb8-41aa-a8bf-c162e8bbd1b3@googlegroups.com>
Cancel-Lock sha1:rykGfmKrOKkaMO/0RuLsLq9C5oo=
X-NNTP-Posting-Host eJwFwQkBACAIA8BMMD7jILj+EbxzhMSkhYc5nTI9pYcxCq96MnsHRIF77aAVNN0MVj5mfyiPEaM=
Xref csiph.com comp.lang.javascript:27399

Show key headers only | 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