首页 > 解决方案 > javascript在推送时修改数组内对象的键值

问题描述

我正在尝试有条件地将对象推送到数组中......
并且当条件不满足时。我想将特定键的值更改为我要推送的对象。事情是这样的……

var temp = [];
status.forEach(status => {
    event.forEach(event => {
        if (status.id == event.status_id) {
            temp.push({status_id : event.status_id, data : event})
        } else if (event.action_id == null) {
            temp.push({status_id : null, data : event}) 
            //Now, what I want is to change the `status_id` of the `event` that I am about to push into the data array into NULL.
        }
    })
})

标签: javascriptarrays

解决方案


推荐阅读