嘿,我在 React Native 中创建了我的第一个应用程序,但遇到了一些麻烦,我只是想知道如何从本地存储中检查对象的特定值。这是我目前所拥有的,我知道它不是那么多。
handleClick = (item)=>{
store.get('myobject').then((res) =>
console.log(res)
)
这是我的 res 对象:
[
{ id: '456', p: 'hey' },
{ id: '464', p: 'ho' },
{ id: '467', p: 'lets' },
{ id: '263', p: 'go' }
]
例如,我想知道对象中是否包含 id 467。
最佳答案
你可以使用 Array 的 some
方法:
var res = [
{ id: '456', p: 'hey' },
{ id: '464', p: 'ho' },
{ id: '467', p: 'lets' },
{ id: '263', p: 'go' }
];
var found = res.some(item => item.id === '467');
console.log(found);
本质上,正如 here 所述
The some() method tests whether at-least one element in the array passes the test implemented by the provided function.
关于javascript - 如何检查对象的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46435527/