gpt4 book ai didi

javascript - 从对象数组中删除一个属性

转载 作者:行者123 更新时间:2023-11-30 07:00:08 25 4
gpt4 key购买 nike

我想从对象数组中删除一个属性

"[{"name":"vv","age":"12","id":"123"},{"name":"v2","age":"13","id":"123"},{"name":"v3","age":"123","id":"124"}]"  

我想从数组中删除年龄属性我的输出应该是

[{"name":"vv","id":"123"},{"name":"v2","id":"123"},{"name":"v3","id":"124"}]" 

最佳答案

您可以使用array.mapdestructuringrest:

var arr = [{"name":"vv","age":"12","id":"123"},{"name":"v2","age":"13","id":"123"},{"name":"v3","age":"123","id":"124"}];

arr = arr.map(({ age, ...rest}) => rest);

console.log(arr);

关于javascript - 从对象数组中删除一个属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50349048/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com