remove elements from array that has same value from other array

The solution for “remove elements from array that has same value from other array” can be found here. The following code will assist you in solving the problem.

// array which holds all values
const namesArr = [“Lily”, “Roy”, “John”, “Jessica”];
const namesToDeleteArr = [‘Roy’, ‘John’]
const namesToDeleteSet = new Set(namesToDeleteArr);

const newArr = namesArr.filter((name) => {
return !namesToDeleteSet.has(name);
});

console.log(newArr); // [“Lily”, “Jessica”]

//////////// OR //////////////////////////

function arr(integerList, valuesList){
return integerList.filter(element => {
return valuesList.indexOf(element) === -1
})
}

console.log(arr([1, 1, 2 ,3 ,1 ,2 ,3 ,4], [1, 3])) // [ 2, 2, 4 ]

//////////// OR /////////////////////////

function arr(a, valuesList){
const newArr = []
for (let i = 0; i < a.length; i++){ if (!valuesList.includes(a[i])) newArr.push(a[i]) } return newArr } console.log(arr([1, 1, 2 ,3 ,1 ,2 ,3 ,4], [1, 3]))

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in