I’m attempting to map an array from this:
[
{
"person_1": "jim",
"person_2": "bob"
}
]
to this:
people: [
{
"person": "jim"
},
{
"person": "bob"
}
]
Right now, my map method is to select each of the values, but it seems inefficient:
const ogArray = [{
"person_1": "jim",
"person_2": "bob"
}]
const newArray = ogArray.map((person) => {
return {
people: [{
person: person.person_1
},
{
person: person.person_2
}
]
}
});
console.log(newArray);
The above method works but it’s not DRY and I wish I could select each object with a wildcard like person_*