Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

397
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!