javascript string to array 1

javascript string to array

// our string
let string = 'ABCDEFG';

// splits every letter in string into an item in our array
let newArray = string.split('');

console.log(newArray); // OUTPUTS: [ "A", "B", "C", "D", "E", "F", "G" ]

Here is what the above code is Doing:
1. We create a variable called string and assign it the value of ‘ABCDEFG’.
2. We create a variable called newArray and assign it the value of the string variable split into an array.
3. We log the newArray variable to the console.

Similar Posts