Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const arr = [{"id":"Lenovo-21910310001","name":"Batrei ","price":"","amount":"1","cut":"","disc":"","pay":"0"},{"id":"Lenovo-21910310001","name":"Batrei ","price":"","amount":"3","cut":"","disc":"","pay":"0"},{"id":"Samsung-21910310002","name":"Chip Power Ac Dan Dc ","price":"600","amount":"5","cut":"","disc":"","pay":"600"}]
- const filteredArr = arr.reduce((acc, current) => {
- let index;
- const x = acc.find((item,i) => {
- index = i;
- return (item.id === current.id)
- });
- if (!x) {
- console.log(current)
- return acc.concat([current]);
- } else {
- acc[index] = current
- return acc;
- }
- }, []);
- console.log(filteredArr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement