-1

For example:

const arr = ['ab', 'cdef', 'ghi']

const split = [['a', 'b'], ['c', 'd', 'e', 'f'], ['g', 'h', 'i']]

How can I do that in Javascript? I'm struggling a little. If anyone could help, I would appreciate it.

2
  • map and split... Commented Jul 6, 2018 at 19:13
  • 1
    What have you tried? Please show your code. Commented Jul 6, 2018 at 19:15

3 Answers 3

1

You can use .map() and Spread Syntax:

const data = ['ab', 'cdef', 'ghi'];

const result = data.map(s => [...s]);

console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

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

Comments

0

Map the items and using an empty string to split them.

const arr = ['ab', 'cdef', 'ghi']

let result = arr.map(i => i.split(''))

console.log(result)

Comments

0

Simply use Array.map()

const arr = ['ab', 'cdef', 'ghi']



const result = arr.map((a)=>a.split(""));

console.log(result);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.