I want to pass the array of string names in to the function and be able to generate the array of objects based on that.
Say I am passing { 'id', 'title' } and as an output I am getting
[
{
id: '1',
title: 'o1'
},
{
id: '2',
title: 'o2'
},
]
I am kind of stucked as not sure how would you take the array of stirngs and convert its elements in to an object
export function getItems(names) {
const a: any[] = [];
for (let i = 0; i < 5; i++) {
// need to produce 5 objects here like:
// {
// id: '1',
// title: 'o1'
// }
a.push(object);
}
return a;
}
thoughts?
${i+1}, title:o${i+1}});1to5