2

I'm making a simple program that jumbles up the letters in words. I want to split every word into an array, within the existing one. i.e.

    ['hello','my','name','is','Anders']

    [['h','e','l,'l','o'],['m','y'],['n','a','m','e'],['i','s'],['A','n','d','e','r','s']

So how would I go about doing this?

2
  • 2
    Split all members with empty character. Commented Aug 23, 2017 at 18:50
  • Where are you stuck? Do you not know how to transform an array by transforming each element? Do you not know how to split a string into its component characters? Commented Aug 23, 2017 at 20:15

3 Answers 3

2

Here:

var arr = ['hello','my','name','is','Anders', '🍺'];
var res = arr.map(e => e.split(""));

console.log(res)

Sign up to request clarification or add additional context in comments.

Comments

2

You could use the spread syntax ... and take single characters.

var array = ['hello','my','name','is','Anders', '🍺'],
    splitted = array.map(s => [...s]);
    
console.log(splitted);

Comments

0

You can use the Array.map function and the String.split, so your code would be like this:

phrase = ['hello','my','name','is','Anders']
phrase.map(x => x.split(""))

2 Comments

Can you give an example where this code could fail?
Any supplementary-plane character such as 💩.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.