Opeyemi Jonah
Opeyemi Jonah

Reputation: 11

Array manipulation with nested arrays

let names = ['Ayomide',['Tolu',['Tola',['Chuka',['Dan']]]]]; How can I manipulate each element in this nested array. It's all index 0 and 1. Trying to figure out how to loop through this to get the elements individually, thanks

Upvotes: 1

Views: 85

Answers (1)

dave
dave

Reputation: 64677

You could use name.flat(Infinity) to flatten it to a single array (Infinity tells it to go as deep as necessary), and then you can just use .forEach or whatever

let names = ['Ayomide',['Tolu',['Tola',['Chuka',['Dan']]]]];
console.log(names.flat(Infinity))

Upvotes: 1

Related Questions