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.
You can use [Array#floatMap()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) and [String#match()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Match):

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

const arr = temp2.flatMap(([s]) => s.match(/\S+/g))
console.log(arr.length)
```

Or [Array#reduce()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reduce) and [String#match()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/Match):

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

const total = temp2.reduce((a, [c]) => a + c.match(/\S+/g).length, 0) 
console.log(total)
```