{
"June": [
{
"id": "59361b2fa413468484fc41d29d5",
"is_new": false,
"name":"John"
"updated_at": "2017-06-07 10:52:05",
}
]
}
我有上面的对象,它内有对象数组,我试图检查'六月',有没有is_new,但失败?迭代使用对象键和findIndex失败
const has_any_is_new = Object.keys(arr).map(obj =>
arr[obj].map(obj2 => obj2.findIndex(o => o.is_new) > -1)
);
的可能的复制[迭代通过对象属性(https://stackoverflow.com/questions/8312459/iterate-through-object-properties) – Michelangelo
你忘了一个逗号在'name'属性之后。你也可以在'updated_at'后面删除逗号。 – Chris
而不是使用'findIndex(...)> -1',你应该做一些(...)' – Bergi