gpt4 book ai didi

javascript - 从数组中删除部分

转载 作者:行者123 更新时间:2023-11-28 11:56:50 25 4
gpt4 key购买 nike

我有以下数组:

KHWArray = [{"date":"23 Jan 14","hours":12,"mins":"31","score":22},
{"date":"23 Jan 14","hours":12,"mins":"36","score":22},
{"date":"23 Jan 14","hours":12,"mins":"44","score":22}
]

如何从所有数组中删除小时和分钟部分,以便只留下日期和分数。

我研究过拼接和删除,但似乎无法实现

最佳答案

您的数组元素是对象,而不是数组,并且没有内置函数来切片对象。不过写起来很容易:

function removeKeys(obj, keys) {
keys.forEach(function(key) { delete obj[key] });
return obj
}

然后

KHWArray = KHWArray.map(function(elem) {
return removeKeys(elem, ['hours', 'mins'])
})

http://jsfiddle.net/HZDaX/

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

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