Honestly, I don't know how to explain this problem. I am trying to explain the problem with an example. Suppose I have two array like this
const columns = [
{name: 'total_sent', title: 'Total Sent'},
{name: 'date', title: 'Date'},
{name: 'total_post', title: 'Total Post'},
];
const tableData = [
{id: 1, total_post: 101, action: 'deleted', date: new Date(), total_sent: 200},
{id: 2, total_post: 401, action: 'deleted', date: new Date(), total_sent: 250},
{id: 3, total_post: 151, action: 'edited', date: new Date(), total_sent: 110},
{id: 4, total_post: 361, action: 'deleted', date: new Date(), total_sent: 20},
{id: 5, total_post: 231, action: 'edited', date: new Date(), total_sent: 260},
];
Now I want a new array like tableData
but the objects should have only total_sent
, total_post
, and date
property. These selected properties are from the columns
array.
expected output has to be like this
const newArr = [
{ total_post: 101, date: new Date(), total_sent: 200 },
{ total_post: 401, date: new Date(), total_sent: 250 },
{ total_post: 151, date: new Date(), total_sent: 110 },
{ total_post: 361, date: new Date(), total_sent: 20 },
{ total_post: 231, date: new Date(), total_sent: 260 },
];
map and filter method are more preferable.