Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
// array which holds all values
const namesArr = ["Lily", "Roy", "John", "Jessica"];
// array of values that needs to be deleted
// from the namesArr
const namesToDeleteArr = ["Roy", "John"];
// make a Set to hold unique 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"]
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers