Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

Delete array inside another array

// array which holds all values
const namesArr = ["Lily", "Roy", "John", "Jessica"];

// array of values that needs to be deleted
const namesToDeleteArr = ["Roy", "John"];

// make a Set to hold values from namesToDeleteArr
const namesToDeleteSet = new Set(namesToDeleteArr);

// use filter() method
// to filter only those elements
// that need not to be deleted from the array
const newArr = namesArr.filter((name) => {
  // return those elements not in the namesToDeleteSet
  return !namesToDeleteSet.has(name);
});

console.log(newArr); // ["Lily", "Jessica"]
Source by melvingeorge.me #
 
PREVIOUS NEXT
Tagged: #Delete #array #array
ADD COMMENT
Topic
Name
3+2 =