搜索對象的屬性比方說,我有一個這樣的對象:的JavaScript - 由項,並添加其值設置爲數組
var object = {
"Defender": {
"player-1868": {
"birthdate": "1 July 1996",
"club_country": "IQ",
"club_id": 171,
"club_name": "Erbil",
"forename": "Burhan Jumaah",
"id": 1868,
"league_id": 12,
"league_name": "Iraqi Premier League",
"name": "Burhan Jumaah",
"nationality": "iq",
"nationality_full": "Iraq",
"position": "Defender",
"surname": "Razzaq",
"votes": [
"y884F42mLCVdld5V5cMeRpl11gJ2"
]
}
},
"Goalkeeper": {
"player-3076": {
"birthdate": "15 December 1985",
"club_country": "QA",
"club_id": 1,
"club_name": "Lekhwiya",
"comments": [
{
"comment": "xxx",
"name": "guy tester",
"photoURL": "http://pbs.twimg.com/profile_images/855450315704979460/RGiq07D7_normal.jpg",
"time": 1496529030321,
"user": "y884F42mLCVdld5V5cMeRpl11gJ2"
}
],
"forename": "Qasem Abdulhamed",
"id": 3076,
"league_id": 1,
"league_name": "Qatar Stars League",
"name": "Qasem Burhan",
"nationality": "qa",
"nationality_full": "Qatar",
"position": "Goalkeeper",
"surname": "Burhan",
"votes": [
"y884F42mLCVdld5V5cMeRpl11gJ2"
]
},
"player-3532": {
"birthdate": "2 April 1992",
"club_country": "SA",
"club_id": 18,
"club_name": "Al Ittihad",
"forename": "Fawaz",
"id": 3532,
"league_id": 2,
"league_name": "Saudi Professional League",
"name": "Fawaz Al Qarni",
"nationality": "sa",
"nationality_full": "Saudi Arabia",
"position": "Goalkeeper",
"surname": "Al Qarni",
"votes": [
"y884F42mLCVdld5V5cMeRpl11gJ2"
]
}
}
};
我將如何使用lodash
,遍歷該對象,並添加每次財產id
出現在player-xxxxxx
的對象鍵中,將該值添加到數組中。從本質上講,讓所有的球員ID在一個array
?
預計結果是「[1868,3076,3532]」?你可以包括你嘗試解決問題的'javascript'嗎? – guest271314
SO不是免費的編碼服務。你必須嘗試自己解決問題。如果無法正常工作,請發佈您嘗試的內容,我們會幫助您解決問題。 – Barmar
你可以將標題從'Javascript -'改爲'Lodash'嗎?使其對您的問題的欺騙性降低。 –