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