Home  >  Article  >  Web Front-end  >  Introduction to the method of deleting array elements or object elements in es6 (code)

Introduction to the method of deleting array elements or object elements in es6 (code)

不言
不言forward
2019-03-21 11:18:115236browse

This article brings you an introduction (code) about the method of deleting array elements or object elements in es6. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Delete array elements

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)

2. Delete object elements

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)

The above is the detailed content of Introduction to the method of deleting array elements or object elements in es6 (code). For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete