简体   繁体   中英

Parse a string representation of an array of arrays, into 2 separate arrays of arrays that are numbers

I can think of how to do this but it would get extremely complicated. So I have to turn this:

[[[0,0],[0,1],[0,2]], [[1,0],[1,1]]]

into 2 arrays:

The first would be: [[0,0], [0,1], [0,2]] - An array of arrays of numbers

The second would be: [[1,0], [1,1]] - Another array of arrays of numbers

How can I do this simply and efficiently without doing a whole bunch of string methods and checking?

You can do something like this:

let x = "[[[0,0],[0,1],[0,2]], [[1,0],[1,1]]]"
y = JSON.parse(x)

and y would be array of arrays.

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