JavaScript Code

How to split string into array of characters?


Problem Statement

given a string, split the string into an array of characters

Solution

to split string str into an array of characters, call String.split() method on the string str, and pass empty string as separator (argument)

str.split('')

Example

1. split string 'apple' into array of characters

let name = 'apple';
let output = name.split('');
console.log(output);