How to change the array structure

I have an array like this

array =  [{name: 'John'},{age: 20},[{degree: "any"}, {college: 'any'}]]

I want to change this array into something like this..

array =  [{name: 'John'},{age: 20},{degree: "any"}, {college: 'any'}]

variable array is returned from different recursive functions, degree and college is returned from single function as an array of object.

>Solution :

array =  [{name: 'John'},{age: 20},[{degree: "any"}, {college: 'any'}]]

console.log(array.flat())

flat() solves your problem.

Leave a Reply