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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -