I have an array:
const data = [
{location: "Phnom Penh", sale: 1000 },
{location: "Kandal", sale: 500 },
{location: "Takeo", sale: 300 },
{location: "Kompot", sale: 700 },
{location: "Prey Veng", sale: 100 },
{location: "Seam Reap", sale: 800 },
{location: "Null", sale: 0}
];
and this is my function filter:
function getSale(data, arr) {
return data
.filter(el => arr.includes(el.location))
}
arr = getSale(data, ['Phnom Penh', 'AA', 'Kompot', 'BB']);
console.log(arr);
result: [{
location: "Phnom Penh",
sale: 1000
},
{
location: "Kompot",
sale: 700
}
]
If 'AA' not found in filter I want it get the 'Null' Object.
My purpose I want the result like this:
result: [
{location: "Phnom Penh", sale: 1000},
{location: "Null", sale: 0},
{location: "Kompot", sale: 700},
{location: "Null", sale: 0}
]
How I do? Thanks for help.
