Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda