1<script>
2var names = 'Harry,John,Clark,Peter,Rohn,Alice';
3var nameArr = names.split(',');
4console.log(nameArr);
5
6// Accessing individual values
7alert(nameArr[0]); // Outputs: Harry
8alert(nameArr[1]); // Outputs: John
9alert(nameArr[nameArr.length - 1]); // Outputs: Alice
10
11var str = 'Hello World!';
12var chars = str.split('');
13console.log();
14
15// Accessing individual values
16alert(chars[0]); // Outputs: H
17alert(chars[1]); // Outputs: e
18alert(chars[chars.length - 1]); // Outputs: !
19</script>
1// our string
2let string = 'ABCDEFG';
3
4// splits every letter in string into an item in our array
5let newArray = string.split('');
6
7console.log(newArray); // OUTPUTS: [ "A", "B", "C", "D", "E", "F", "G" ]
1//split into array of strings.
2var str = "Well, how, are , we , doing, today";
3var res = str.split(",");
1const str = 'Hello!';
2
3console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
1// If you want to split on a specific character in a string:
2const stringToSplit = '01-02-2020';
3console.log(stringToSplit.split('-'));
4// ["01", "02", "2020"]
5
6// If you want to split every character:
7const stringToSplit = '01-02-2020';
8console.log(Array.from(stringToSplit));
9// ["0", "1", "-", "0", "2", "-", "2", "0", "2", "0"]
1const string = "Hello!";
2
3console.log([...string]); // ["H", "e", "l", "l", "o", "!"]