-2

I am having the below array

const a1 = [1,2,3];

and want to convert it into

const b1 = [{id:1},{id:2},{id:3}];

Is there a quick way in doing in javascript

2

1 Answer 1

4

Use Array.map()

const a1 = [1,2,3];
const b1 = a1.map(val => ({id: val}));
console.log(b1);

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

1 Comment

A question that is solvable by a 5 second search? Imho -> Yes. That question shouldn't exist in the first place and doesn't deserve an answer other than a close vote (needs details or as duplicate because this will then definitely have been asked and answered before)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.