Home > Web Front-end > JS Tutorial > 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)

不言
Release: 2019-03-21 11:18:11
forward
5257 people have browsed it

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)
Copy after login

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)
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template