数组操作

1.数组赋值


this.Arr1= this.Arr2.map(item => {
    
    item = {...item}  //数组赋值给新数组
    item = {...item, answer:'123'}  //数组赋值并新增对象
    return item

})

2.数组过滤

this.Arr1 = this.Arr2.filter((item) => {
    return item.isSelect === true;   //过滤条件
});

3.向数组对象新增键值对

this.Arr.push({ name: 'value', name: 'value' });

4.指定数组对象排第一位

this.Arr.unshift(this.Arr[index]);  //在首位增加指定对象
this.Arr.splice(index+1, 1);  //删除原本那条对象

5.指定位置插入对象

Arr.splice(index, 0, 插入对象)    //index:插入位置, 0:删除0个对象

6.检测数组元素中是否有元素符合指定条件

let status =  this.thanksList.some((item)=>{
    return item.contentText == this.thanksText   //判断条件
})     //满足则status为true,否则为false
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。