1

i got an array of numbers [12345,345653,456356]but i need to convert this to something like [[1232131],[234324],[67657]]for using a CSV react component tool that reads data using this format. Do you got some idea how to make this? i tried this using push but i dont get the correct format.

2 Answers 2

2

You can simply use .map() to create a new array based on existing one:

let input = [12345,345653,456356];
let output = input.map(x => [x]);
console.log(output);

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

Comments

0

Not as elegant as mickl's map() but if you prefer an oldfashioned loop:

let input = [ 1, 2, 3 ];
let output = [];

for (let i = 0; i < input.length; i++) {
  output.push([ input[i] ]);
} 

console.log(output);

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.