It divides the input string into an array of substrings, breaking the input string at each occurrence of the separator.
If the separator is not found in the input string, the method returns an array containing the entire input string as its single element.
const inputString = 'firstname.lastname@example.org'; const separator = '.'; const resultArray = inputString.split(separator); console.log(resultArray);
In this example, we used the split() method to break the inputString into an array of substrings, using the separator variable (‘.’) as the delimiter. The resulting array contains two elements: ‘nshah@gmail‘ and ‘com’.
Niva Shah is a Software Engineer with over eight years of experience. She has developed a strong foundation in computer science principles and a passion for problem-solving.