【发布时间】:2022-01-12 08:06:32
【问题描述】:
我有一个带有嵌套对象的 JS 数组作为“任务列表”。它们每个都添加了不同的紧急属性。现在我的函数需要找到最高的紧急值 - 将其设置为一个变量,然后将其从数组中删除。
我被困在从原始数组中删除它。我遇到的麻烦可能只是找到索引:
function newTask() {
// reducing the "task list" to just the highest urgency
let maxObj = taskList.reduce((max, obj) => (max.stockUrgency > obj.stockUrgency) ? max : obj);
outputNewtask = JSON.stringify(maxObj, null, 4);
let index = taskList.indexOf("outputNewtask")
console.log(index)
【问题讨论】:
-
你的
taskList怎么样? -
你可以分享
taskList的例子吗?另请注意,outputNewtask将是一个 JSON 字符串不是对象,taskList极不可能包含具有该确切字符串的条目。
标签: javascript arrays object reduce