es6刪除數組元素或者對象元素

一,刪除數組元素數組

let arr = [
    {name:'黎明',id:21111},
    {name:'王小二',id:1111},
    {name:'大小二',id:3222}
  ]
arr.splice(arr.findIndex(item => item.id === 3222), 1)

arr.filter(obj=>obj.id!==3222)

二,刪除對象元素code

let arr = {
    name: '黎明',
    id: 1111,
    age: 24
};

方法1:

const personUnkonwAge = (({name, id}) => ({name,id}))(arr)
console.log(personUnkonwAge)
console.log(arr)

方法二:

let {name, ...personUnknowName} = arr
console.log(personUnknowName)
相關文章
相關標籤/搜索