Split string into individual characters?

This code

var chars = "the".split(" "); 
  console.log(chars);

seems to put the entire word “the” into index 0 of an array.

But I want it to print out like [‘t’, ‘h’, ‘e’]

You have passed it a string with a space in it - that is you telling it to break it up using the spaces as delimiters. If you send it nothing, it will just break it into every character, split();

1 Like
var chars = "the".split(); 
  console.log(chars);

produces the same result.

You will want to look at the second example from the docs.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.