I have a collection of objects structured in the following way:
let list = [
{
'items': [
'item 1',
'item 2'
]
},
{
'items': [
'item 3'
]
}
]
My goal is to flatten these nested arrays into a single array like this:
['item 1','item 2','item 3']
Is there a specific JavaScript function that can help me achieve this desired output?
I attempted using the map function as follows:
list.map(i => i.items)
However, the result I obtained was:
[["item 1","item 2"],["item 3"]]
IMPORTANT: I am seeking either an existing function or a solution encapsulated within a function, enabling me to simply make a call to the function without needing to manually implement the loop logic.