0

Convert each element of array into separate array and push into one array.

inputArray = ['One', 'Two', 'Three']

Required Output

outputArray = [['One'],['Two'],['Three']]

By using ES6 how to get this output?

0

2 Answers 2

3

You an use array.map to do that:

const inputArray = ['One', 'Two', 'Three'];
const result = inputArray.map(x => [x]);
console.log(result);

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

Comments

0

You mean a simple map of each element? That can be done very quickly like so

const outputArray = inputArray.map(el => [el]);

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.