I am trying to convert an array of numbers to array of objects. What is the easiest way to do this?
myArray = [1,2,3];
myObject = convertToObjects(myArray);
convertToObjects= (items) => {
let listOfItems = [];
let convertToObj = items.map(item, idx => {
let key = item;
listOfItems.push({ key });
});
return listOfItems;
}
Thank you!
Expected output:
[
{key: 1},
{key: 2},
{key: 3}]
myArray.map(x => ({key:x}))