How we remove object from an Array based on another array in Angular 6

  • A+
Category:Languages

I have two arrays like this:

var skillArray = [ {ID: 1, name: "الغطس"}, {ID: 2, name: "الحريق"}, {ID: 3, name: "المعالجة"}, {ID: 4, name: "الميكانيكا"}, {ID: 5, name: "السيول"}, {ID: 6, name: "التغريز"}, {ID: 7, name: "الكهرباء"}, {ID: 8, name: "الاحتفالات"}, {ID: 9, name: "المناسبات"}, {ID: 10, name: "الصلاة"} ]  var splitstr = ["9", "7"]

As you can see, ID 9 & 7 match and I want to be able to remove them from skillArray. How would I write this?

 


var skillArray = [ {ID: 1, name: "الغطس"}, {ID: 2, name: "الحريق"}, {ID: 3, name: "المعالجة"}, {ID: 4, name: "الميكانيكا"}, {ID: 5, name: "السيول"}, {ID: 6, name: "التغريز"}, {ID: 7, name: "الكهرباء"}, {ID: 8, name: "الاحتفالات"}, {ID: 9, name: "المناسبات"}, {ID: 10, name: "الصلاة"} ]  var splitstr = ["9", "7"]  const removeSkills = (source, removeList) => {   return source.reduce((prev, curr) => {     if(!removeList.includes(curr.ID.toString()) ){       return prev.concat(curr)     }     return prev   }, []) } const result = removeSkills(skillArray, splitstr) console.log(result)

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: