Convert an array object to separate separate object without object key. I like to
const arr = [
{ public_id: 'apple', secure_url: 'one' },
{ public_id: 'banana', secure_url: 'two' },
{ public_id: 'orange', secure_url: 'three' }
];
And i need to convert to
{ public_id: 'apple', secure_url: 'one' },
{ public_id: 'banana', secure_url: 'two' },
{ public_id: 'orange', secure_url: 'three' }
3
Answers
The second one is not a valid data structure.
You could however convert it to something like this:
like this:
I did not get what you meant by saying seperate object without object key.
It is comletely fine to store and reach objects in/from array, but if what you want is to iterate through objects in array then you can use built-in
map()
orforEach()
functions.You can use destructuring to extract the array entries into individual variables: