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

184
Vistas
How can I get this to show the index of all the numbers in my parameter

so for example if i do removeFromArray([1, 2, 3, 4], 2, 3) it should return [1, 4] right now the index variable is only showing the index of the first argument of remove

function removeFromArray(arr, ...remove) {
    let index = arr.indexOf(...remove);
    let amountRemove = arguments.length - 1;

    arr.splice(index, amountRemove);



    return arr;
}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Hi,

First: indexOf method work only with one parameter. Consecutive it result -1

Second: amountRemove variable that you are using to delete mean that it must you want delete from the array is consecutive and not separated and this is not good experience.

Simply to solve this problem using loop or forEach or any method make loop on the values of the array

and his your code fixed

function removeFromArray(arr, ...remove) {
    remove.forEach(element => {
        let index = arr.indexOf(element);
        arr.splice(index, 1);
    })
    return arr;
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You looking for something like that?

function removeFromArray(arr, ...remove) {    
    let temp = []
    arr.forEach(n => {
      if (!remove.includes(n) ) {        
        temp.push(n) 
      }
    });
    return temp;
}

console.log('res',removeFromArray([1, 2, 3, 4], 2, 3) )

about 4 years ago · Juan Pablo Isaza Denunciar
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