JS-152-Objects-Arrays
  • Introduction
  • 04-Objects
    • OOP-Basics
      • Overview
      • Coding the Example
    • Prototypes
      • Object Prototypes
      • Prototypes Continued
    • Inheritance
      • Inheritance
    • Synopsis
      • Synopsis
    • Challenges
    • Solutions
      • Constructor Function
        • Person Constructor
        • Explanation
      • Inheritance Challenge
        • Code
        • Explanation
      • Family Challenge
        • Child
        • Pet
  • 05-Arrays
    • Array Basics
      • Array Overview
      • Creating an Array
      • Individual Elements and Length
      • Iterating Over Arrays
    • Array Methods
      • Methods Overview
      • .join() Method
      • .reverse() Method
      • .split() Method
      • .replace() Method
      • .splice() Method
      • .map() Method
      • .indexOf() Method
      • .filter() Method
      • .every() Method
    • Palindrome Algorithm
    • Array Challenges
    • Solutions
      • First and Last
        • First Element
        • Last Element
      • Most Frequent
      • Largest and Smallest
        • Single Array
        • Multiple Arrays
      • Missing Number
      • "Arrays" in the DOM
      • Sorting
        • Bubble Sort
        • Selection Sort
    • Resources
Powered by GitBook
On this page
  1. 05-Arrays
  2. Array Methods

.split() Method

Use the .split() method when you want to split up a string into chunks. Let's say you wanted to split the sentence "The quick brown fox jumps over the lazy dog" into nine separate elements.

var str = "The quick brown fox jumps over the lazy dog.";

//splitting by whitespace
var strSplit = str.split(" ");

console.log(strSplit);

Output

[ 'The', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dog']

Now that you have the array, you can determine the number of words in a sentence. You could use this knowledge to grab a first name from a person's full name. In the next module, we'll use it to split a word into individual characters. Also, notice the empty " " in str.split? You can split a string using any character you want!

Previous.reverse() MethodNext.replace() Method

Last updated 7 years ago