Reactjs 使用find更改数组中的特定值。自然反应

Reactjs 使用find更改数组中的特定值。自然反应,reactjs,react-native,Reactjs,React Native,我想更改此对象数组中的特定值, 我知道怎么做: let array = [{7: 10}, {10: 9}, {8: 5}, {3: 4}, {6: 7}] 谢谢你你可以试试这个 array.find( (item, index) => Object.keys(item) === 7 ? console.log('I would like to delete this object or change its value = ' + Object.values(item)) : n

我想更改此对象数组中的特定值, 我知道怎么做:

let array = [{7: 10}, {10: 9}, {8: 5}, {3: 4}, {6: 7}]
谢谢你

你可以试试这个

array.find(
(item, index) => Object.keys(item) === 7 
? 
console.log('I would like to delete this object or change its value = ' + Object.values(item))
: 
null
);

这里有一个例子。您可以通过param将其设置为函数,而不是“7”

// Find the index you want to change
const index = array.findIndex(element => {
    return Object.keys(element) == 7
})

//assign it with new value
array[index] = {5:6}

可以删除该对象吗?可以,您可以使用splice。设数组=[{7:10},{10:9},{8:5},{3:4},{6:7}];array.forEach((item,index)=>{if(Object.keys(item.find)(key=>key=='7'))array.splice(index,1);});console.log(数组);
let array = [{7: 10}, {10: 9}, {8: 5}, {3: 4}, {6: 7}];

array.forEach(
    (item) => {
        if (Object.keys(item).find(key => key === '7'))
            item['7'] = 8
    });

console.log(array);