take a look at this example:
let my_array = [1,2,4,5,6,7,8]
test = my_array.map(element=>{
if(element!==1){
return element
}
})
console.log(test)
why map() function always return something if the statement does not match?
I know map function iterate over the indexes of array. but why returns null? we said return only if the statement is true.
how we can avoid null in return of map()?
update: I needed combination of map() and filter():
let my_array = [1, 2, 4, 5, 6, 7, 8]
test = my_array
.filter(element => element !== 1)
.map(element => element * 2);
console.log(test)