Filtering customers state array based on array of ids in javascscript/react.
const activeCustomerIdSet = [3,4,9];
//customers is array of customer data in my case its array value is bit different, just to note.
const filteredActiveCustomersIds = Array.from(activeCustomerIdSet) || [];
let nonActiveCustomers = [];
let filterCustomer = [...customers];
if (filteredActiveCustomersIds.length) {
for (let cid of filteredActiveCustomersIds) {
filterCustomer = filterCustomer?.filter(cust => {
if (+cust?.value?.id !== cid) {
return cust;
}
});
}
nonActiveCustomers = [...nonActiveCustomers,
filterCustomer];
}
console.log({ filteredActiveCustomersIds, customers, nonActiveCustomers });
Hope you find useful in your search!
Keeping it short simple and straight.
Happy coding!
In today’s fast-paced work environment, meetings are essential but can often feel unproductive. However, by…
Gold is one of the most coveted precious metals in the world, adored for its…
Gold, the shimmering metal synonymous with wealth, power, and beauty, has been deeply intertwined with…
How to Onboard an Intern in a Small, Individual-Based Company Hiring an intern can be…