首页 > 其他分享 >数组 filter 另一个数组(两个数组中找出相似的数据)

数组 filter 另一个数组(两个数组中找出相似的数据)

时间:2022-12-08 16:33:06浏览次数:47  
标签:tricc1 找出 tricc2 const router1 filter 数组

       const arr1 = [
              '/router1/tricc1',
              '/router1/tricc2',  
              '/router2/tricc1',
              '/router2/tricc2',    
              '/router3/tricc1',
              '/router3/tricc2',      
       ]         
        
        const arr2 = [
               'router1', 
         ]
       
        const  intervenemenuarr = arr1.filter(item => {
                        return arr2.find(prop => {
                            return item.includes(prop);
                        });
                  });                    
        
        console.log(intervenemenuarr)    // ['/router1/tricc1','/router1/tricc2',]
 

  

标签:tricc1,找出,tricc2,const,router1,filter,数组
From: https://www.cnblogs.com/qing1224/p/16966486.html

相关文章