简体   繁体   中英

conversion of 2d array to json object in javascript

consider my array in nodejs as

[x:["xyz","abc","uvw","efg"],y:["wer","mno","sdk"]]

when i tried converting this array using JSON.stringify() i could get only [] in return.

is there any way to store multiple values like array in Object data type.

You can't use array with a non-numeric index. In your case you should use an object instead: {x:["xyz","abc","uvw","efg"],y:["wer","mno","sdk"]} .

Be aware that you can get keys of this object with Object.keys(obj) . It returns an array ['x', 'y'] and you can iterate through the object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM