I have a collection of objects and I'm looking for a way to empower the user to choose which attributes they want to import into the database. Is there a method to map and generate a separate array containing only the selected properties for insertion?
For instance, let's consider the following object array:
[
{name: 'name1', address: 'addr1', phone: '123'},
{name: 'name2', address: 'addr1', phone: '123'},
{name: 'name3', address: 'addr1', phone: '123'},
{name: 'name4', address: 'addr1', phone: '123'},
]
If the user chooses name and phone, the resulting array to be inserted in the database should appear as follows:
[
{name: 'name1', phone: '123'},
{name: 'name2', phone: '123'},
{name: 'name3', phone: '123'},
{name: 'name4', phone: '123'},
]
Is there a way to achieve this efficiently?