javascript - Change array values to number from string -
i have array these values:
var items = [thursday,100,100,100,100,100,100]
i'm grabbing these url query string string values. want columns except first number. array may vary in number of columns, there way set items[0] string, items[n] number?
"...is there way set items[0] string, items[n] number?"
use .shift()
first, .map()
build new array of numbers, .unshift()
add first in.
var first = items.shift(); items = items.map(number); items.unshift(first);
demo: http://jsfiddle.net/ecuju/
we can squeeze down bit this:
var first = items.shift(); (items = items.map(number)).unshift(first);
demo: http://jsfiddle.net/ecuju/1/
Comments
Post a Comment