-1
我有兩個user_id。我需要弄清楚兩個user_ids是否已經屬於一個對話。查找嵌套javascript數組中的匹配值
假設我想搜索user_id 7和4之間的對話,下面的數組會返回空白,因爲7和4不屬於對話。如果我搜索7和8,它會返回一個數組。
我打開lodash和一個班輪的例子。
[
[{
"full_name": "Bob",
"id": 7,
"user_conversations": {
"user_id": 7,
"conversation_id": 1
}
}, {
"full_name": "Sally",
"id": 8,
"user_conversations": {
"user_id": 8,
"conversation_id": 1
}
}],
[{
"full_name": "Suzy",
"id": 6,
"user_conversations": {
"user_id": 6,
"conversation_id": 2
}
}, {
"full_name": "Bob",
"id": 7,
"user_conversations": {
"user_id": 7,
"conversation_id": 2
}
}]
]
回報什麼的陣列? – Marty
遍歷數組,創建7的對話數組,以及4的對話數組。然後查看兩個數組是否有任何共同的值。 – Barmar