Ads by ProfitSence

JavaScript Split Method

Last Updated on Wednesday 5th Oct 2022

JavaScript Split

  • The JavaScript split() method splits a string into an array of sub strings.
  • The split method takes two arguments and they're both optional.
  • One is Seperator and another one is limit
  • Separator - determines the character to use for splitting the string.
  • limit - is an integer specifying the number of splits.Items after this will not be included

javascript split string

Its upto you where and how to split.

					let string = "Hi I'm Your New Friend";
let splitted = string.split(" ");


javascript split string into array


					console.log(splitted[2]); // Your


javascript split string by comma ,

					let string1 = "Hello, How are You today?";
let splitted1 = string1.split(",");

					["Hello","How are You today?"]


Let split a string without a space

					let string2 = "Yesterday";
let splitted2 = string2.split("");

					["Y", "e", "s", "t", "e", "r", "d", "a", "y"];


Let split the string by a letter

  • It Takes letter away
					let string3 = "Yesterday";
let splitted3 = string3.split("e");

					["Y", "st", "rday"];

  • limit is 1
					let string4 = "Yesterday";
let splitted4 = string4.split("e",1);