The split([separator, [limit]]) method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
let a = "hello,hi,bonjour,namaste"; let greetings = a.split(','); console.log(greetings)
[ 'hello', 'hi', 'bonjour', 'namaste' ]
Note that the commas were removed here. Any separator provided will be removed.
If separator is an empty string, str is converted to an array having one element for each character of str.
let a = "hello"; console.log(a.split(""))
[ 'h', 'e', 'l', 'l', 'o' ]
If no separator is provided, the string is returned as is.
let a = "hello world" console.log(a.split())