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" ]
1const string = 'hi there';
2
3const usingSplit = string.split('');
4const usingSpread = [...string];
5const usingArrayFrom = Array.from(string);
6const usingObjectAssign = Object.assign([], string);
7
8// Result
9// [ 'h', 'i', ' ', 't', 'h', 'e', 'r', 'e' ]
10
1const str = 'Hello!';
2
3console.log(Array.from(str)); // ["H", "e", "l", "l", "o", "!"]
1const string = 'word';
2
3// Option 1
4string.split('');
5
6// Option 2
7[...string];
8
9// Option 3
10Array.from(string);
11
12// Option 4
13Object.assign([], string);
14
15// Result:
16// ['w', 'o', 'r', 'd']
17
1let input = "words".split("");
2let output = [];
3input.forEach(letter => {
4 output.push(letter.charCodeAt(0))
5});
6console.log(output) //[119, 111, 114, 100, 115]