Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

remove elements from array that has same value from other array

// 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]))
Comment

PREVIOUS NEXT
Code Example
Typescript :: typescript array of string array 
Typescript :: web.contents timeout 
Typescript :: use sample weights fit model multiclass 
Typescript :: serenity.is center open dialog 
Typescript :: msgpack lite 
Typescript :: React-native suppress the warning "VirtualizedLists should never be nested" 
Typescript :: error TS2531 
Typescript :: vercel react redirects to index html 
Typescript :: preventing letters from being placed in an input ts 
Typescript :: return n elements from list java 
Typescript :: in grunt cannot be loaded because running scripts is disabled on this system 
Typescript :: filter typescript 
Typescript :: How to pass optional parameters while omitting some other optional parameters? 
Typescript :: findbyidandupdate 
Typescript :: nodejs stream write file 
Typescript :: ubuntu display stdouts of processn 
Typescript :: None of the following functions can be called with the arguments supplied. makeText(Context!, CharSequence!, Int) defined in android.widget.Toast makeText(Context!, Int, Int) defined in android.widget.Toast 
Typescript :: typescript object literals 
Typescript :: How to disable form control but keep value 
Typescript :: typescript class example 
Typescript :: setTimeout without arguments 
Typescript :: has apple distribution certificate installed but its private key 
Typescript :: type in typescript 
Typescript :: Please fill in the missing parts of the code to print "I love C++" on the screen. 
Typescript :: how to permit only a few values in dbms 
Typescript :: puts with details ruby 
Typescript :: interface extending mongoose document object does not contain _doc object typescript 
Typescript :: the benefits of deploying a network using a WLC 
Typescript :: typescript custom number no greater than x 
Typescript :: compy mongodb database with indexes 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =