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

400
Visualizações
How can I use map() function to remove elements in an array?

I was trying to create new array which will get elements from "serie" array. I want to remove elements smaller than 10 and multiply elements bigger than 10. I can do this by creating two separate variables with using filter(), but is it possible to do it with a single variable and a function like only using map() or forEach()?

Is there a method which the elements in the map() be thrown directly in a way like element.pop() so this particular element will be deleted without empty array while mapping elements. So for this code I can remove the element if it is lower than 10 and multiply it if it is bigger than 10

let serie = [7,4,9,12,18,21];

var newSerie = serie.map(function(element){

    
  if(element>10) {
   return element*10;
  }else{
    return element;
  }
  
    if(element<10){
    newSerie.splice(serie.indexOf(element),1); 
  }
  

})

console.log(newSerie);

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

Use .filter to remove elements, then apply needed action on them using .map

let serie = [7, 4, 9, 12, 18, 21];

const result = serie.filter(x => x > 10).map(x => x * 10)
console.log(result)

Or in one go using .reduce

const result = serie.reduce((acc, x) => {
  if (x >= 10) {
    acc.push(x * 10)
  }
  return acc;
}, []);
about 4 years ago · Santiago Gelvez 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