Why does javascript map function return undefined?

前端 未结 7 1279
梦谈多话
梦谈多话 2020-12-07 16:24

My code

 var arr = [\'a\',\'b\',1];
 var results = arr.map(function(item){
                if(typeof item ===\'string\'){return item;}  
               });
<         


        
7条回答
  •  春和景丽
    2020-12-07 16:38

    Since ES6 filter supports pointy arrow notation (like LINQ):

    So it can be boiled down to following one-liner.

    ['a','b',1].filter(item => typeof item ==='string');
    

提交回复
热议问题