Question: I have an array of arrays with sentences in each element. I want to end up with one single array with each word split up by spaces and then get the length of the whole array

I know I need to loop through the array and then apply split but is there a better way?

```js
const temp2 = [
  ['this is an array'],
  ['this is a scentence'],
  ['I love stackoverflow']
]
console.log(
  temp2[0][0].split(' ').length // 3 words
)  
```

Answer: 
You can use `reduce()` on the array and split each item in the array

```js
    const temp2 = [
       ['this is an array'],
       ['this is a scentence'],
       ['i love stackoverfloe']
    ]

    const words = temp2.reduce(
      (arr, sentence) => { 
        return [...arr, ...sentence[0].split(' ')]
      }, 
      []
    )
    console.log(words)
```

If you are targeting modern browser, the other answers using `.flat()` and `.flatMap()` are better. If you are targeting older browsers (such as IE) those won't work while reduce is supported.
try this, maybe this is what you want:

```js
const temp2 = [
  ['this is an array'],
  ['this is a scentence'],
  ['i love stackoverfloe']
]

let res = temp2.reduce((prev, next) => {
    const tempArr = next[0].split(" ")
    for (let i = 0; len = tempArr.length, i < len; i ++) {
        prev.push(tempArr[i])
    }
    return prev
}, [])

console.log("res", res)
console.log("res.length", res.length)

```