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)

二,删除对象元素

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)
    原文作者:码厨师长
    原文地址: https://segmentfault.com/a/1190000018594109
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞