How to use array filter() to create new array with the results of run a function for each element in JavaScript

2 Answers

0 votes
const chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'd']
const arr = chars.filter(item => item !== 'd')

document.write(arr);
 

 
    
/*
run:
          
a,b,c,e,f,g 
        
*/

 



answered Nov 6, 2019 by avibootz
0 votes
const chars = ['a', 'b', 'a', 'c', 'd', 'e', 'f', 'g', 'd']
const remove = ['a', 'd']
const arr = chars.filter(item => !remove.includes(item))

document.write(arr);
 

 
    
/*
run:
          
b,c,e,f,g 
        
*/

 



answered Nov 6, 2019 by avibootz
...