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

399
Vistas
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 Respuestas
Responde la pregunta

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 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