首页  >  文章  >  web前端  >  es6删除数组元素或者对象元素的方法介绍(代码)

es6删除数组元素或者对象元素的方法介绍(代码)

不言
不言转载
2019-03-21 11:18:115165浏览

本篇文章给大家带来的内容是关于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)

以上是es6删除数组元素或者对象元素的方法介绍(代码)的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:segmentfault.com。如有侵权,请联系admin@php.cn删除