管理filter和map的区别
相同点 两者不会对原数组进行修改
都会用新的数组承接 便利后的的数组
map 返回的是值 但是filter 直接做判断 为true 才返回
<template>
  <div>
      <button @click="btn">点击</button>
      {{arr}}
      <br>
      {{res1}}
      <br>
      {{res2}}
  </div>
</template>
<script>
export default {
    data(){
      return{
        arr:[2,4,1,5,3,1],
        res1:[],
        res2:[]
      }
    },
    methods:{
       btn(){
            this.res1=this.arr.map(function (item,index,array) {
            // return array[index]; //用这种方法也可以获取到当前处理的元素
                  return item + "0";
            });
            this.res2=this.arr.filter(function (item,index,array) {
               return item>1;
            });
       }
    }
}
</script>
<style>
</style>
 
                    
                     
                    
                 
                    
                 
                
            
         
 
         浙公网安备 33010602011771号
浙公网安备 33010602011771号