Issue
I have this array:
[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]
how can i remove the first parenthesis? i tried with reduce or map but return an error:
Cannot read properties of undefined (reading 'reduce') or Cannot read properties of undefined (reading 'map').
I have to retrieve some data inside it.
Thanks for your help.
Solution
you can use array.flat() here
let x =[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]
let y = x.flat()
console.log(y) // [ { data1: 1, data2: 2 }, { data1: 1, data2: 2 } ]
Answered By - Smriti Shikha
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.