Javascript loop through array keys containing comma seperated values -



Javascript loop through array keys containing comma seperated values -

i trying figure out best way split object has many key value pairs on 800 points ( x , y coordinates)

i split x own array , y separate array can access x lone , y alone.

here construction of points , have attempted

var path = { 0: [41, -73], 1: [41, -74], 2: [42, -75], 3: [43, -76] }; (var key in path) { console.log("key " + key + " has value " + path[key]); }

this log

key 0 has value 41,-73 key 1 has value 42,-74 key 2 has value 43,-75 key 3 has value 44,-76

i need first value stored in own array , sec value array.

for illustration access of x , y such,

var x = [41, 42, 43, 44] var y = [-73,-74,-75,-76]

js fiddle here http://jsfiddle.net/b3j4w9bv/14/

thanks!

you along these lines:

var path = { 0: [41, -73], 1: [41, -74], 2: [42, -75], 3: [43, -76] }; var x_path = []; var y_path = []; for(var key in path) { //console.log("key " + key + " has value " + path[key]); //create split on , x & y var split_path = path[key]; //grab value of split: var x = split_path[0]; var y = split_path[1]; //add coords arrays. x_path.push(x); y_path.push(y); //output result: console.log(x_path); console.log(y_path); }

i haven't tested in terms of perfomance..it might not efficient

fiddle: http://jsfiddle.net/g123vyuv/

javascript arrays html5 object coordinates

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -