我有一个看起来像这样的字典列表:
activityType: "message"
actorFirstName: "name"
actorHeadline: ""
actorId: 131659821
actorLastName: "last"
actorVectorImage:
i18nLastModifiedRelative: "24 days ago"
lastModified: 1561549463000
我想检查列表中的所有字典并找到最近的 lastModified
时间戳,其中 actorId: 131659821
&& activityType: "message"
我正在考虑在 forEach 循环中检查每个键,但这只有在我只需要检查 1 个键:值时才有帮助。
我尝试过类似的方法:
inmailList.forEach((inmail) => {
Object.keys(inmail).forEach((key) => {
if (inmail[key] === 'message')
})
})
这只是告诉我一个值是否是“message”,但它不会检查 actorId
有没有办法一次检查多个键/值?
最佳答案
// filter
let filteredData = inmailList.filter(activity => activity.actorId === 131659821
&& activity.activityType === 'message');
// sort descending
filteredData.sort((a, b) => b.lastModified - a.lastModified);
// take first
let mostRecent = filteredData[0];
关于javascript - 获取字典列表中的最大值,其中字典中存在多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57126372/