repl.it
@Tyledelphia/

Get all words in a string

JavaScript

No description

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
function getAllWords(str) {
  if (str === '') {
    return [];
  }
  let wordArray = [];
  for (let i = 0; i < str.split(' ').length; i++) {
    let words = str.split(' ');
    wordArray.push(words[i])
  }
  return wordArray;
}
  getAllWords('The quick brown fox jumps over the lazy dog');
Native Browser JavaScript