Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

140
Views
Remove multiple elements from an array with splice()

I'm trying to remove multiple elements from an array with .splice() but I am not getting the desired output, any suggestions ?

const removeFromArray = function(arr, ...target) { //taking target as a rest parameter.
    for(let i = 0; i < arr.length; i++ ){
        for(let j = 0; j < target.length; j++){
            if(arr[i] == target[j] && typeof(arr[i]) == typeof(target[j])){
                arr.splice(i , 1); //removing 1 element from i'th index.
            }
        }
    }
    return arr;
}; 

console.log((removeFromArray([1, 2, 3, 4], 3, 2))) //[ 1, 3, 4 ] , should display [1,4]
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!