OneBite.Dev - Coding blog in a bite size

split a string in Javascript

Code snippet on how to split a string in Javascript

  const myString = "Hello World";
  const splitString = myString.split(" ");

This code snippet will split a string into separate strings based on a specified separator. In this example, the specified separator is a space character. The code first creates a variable called myString and assigns the string “Hello World” to it. Then, it creates a second variable called splitString that contains the result of running the split() function on myString. The split() function will break up the string into an array of two strings, each element being one of the words from the original string. The result of running this code snippet will be two strings, “Hello” and “World”.

javascript