2

I have a comma separated string and i want to convert it into multiple arrays. Here is the code i tried but failed to achieve the expected output.

const data = "123,456";
result = data.split(',').map(s => Array.from(s));

console.log(result); // [["1", "2", "3"], ["4", "5", "6"]]

Expected output:

[["123"], ["456"]]
0

2 Answers 2

1

Map it to an array.

const data = "123,456";
result = data.split(',').map(s => [s]);

console.log(result);

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

Comments

0

As epascarello suggests on his comment, try

data.split(',').map(s =>[s]);

Take a look here for more info!

Comments

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.