Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda