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
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
Use Array.map()
const a1 = [1,2,3];
const b1 = a1.map(val => ({id: val}));
console.log(b1);