我收到了以下JSON响应:
{"beatmapset_id":"971561","beatmap_id":"2034200","approved":"3","total_length":"196","hit_length":"186","version":"Easy","file_md5":"9c8eb80f6e245b5b0a0a100bbb3e274c","diff_size":"4","diff_overall":"7","diff_approach":"5","diff_drain":"7","mode":"3","submit_date":"2019-05-14 12:01:13","approved_date":"2019-05-22 15:49:35","last_update":"2019-05-22 11:51:06","artist":"antiPLUR","title":"Runengon","creator":"Raveille","creator_id":"1388767","bpm":"174","source":"osu!","tags":"featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic","genre_id":"1","language_id":"1","favourite_count":"1","rating":"0","playcount":"0","passcount":"0","max_combo":null,"diff_aim":null,"diff_speed":null,"difficultyrating":"1.2615262269973755"},{"beatmapset_id":"971561","beatmap_id":"2034201","approved":"3","total_length":"196","hit_length":"196","version":"Hard","file_md5":"b5fbe1a1444e35ecb7f8f03e2b61986b","diff_size":"4","diff_overall":"8","diff_approach":"5","diff_drain":"8","mode":"3","submit_date":"2019-05-14 12:01:13","approved_date":"2019-05-22 15:49:35","last_update":"2019-05-22 11:51:06","artist":"antiPLUR","title":"Runengon","creator":"Raveille","creator_id":"1388767","bpm":"174","source":"osu!","tags":"featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic","genre_id":"1","language_id":"1","favourite_count":"1","rating":"0","playcount":"27","passcount":"9","max_combo":null,"diff_aim":null,"diff_speed":null,"difficultyrating":"3.590883255004883"},{"beatmapset_id":"971561","beatmap_id":"2034202","approved":"3","total_length":"196","hit_length":"196","version":"Normal","file_md5":"f7f23e1073b508593d98cb50097b0d7e","diff_size":"4","diff_overall":"7.5","diff_approach":"5","diff_drain":"7.5","mode":"3","submit_date":"2019-05-14 12:01:13","approved_date":"2019-05-22 15:49:35","last_update":"2019-05-22 11:51:06","artist":"antiPLUR","title":"Runengon","creator":"Raveille","creator_id":"1388767","bpm":"174","source":"osu!","tags":"featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic","genre_id":"1","language_id":"1","favourite_count":"1","rating":"0","playcount":"0","passcount":"0","max_combo":null,"diff_aim":null,"diff_speed":null,"difficultyrating":"2.367466926574707"},{"beatmapset_id":"971561","beatmap_id":"2039384","approved":"3","total_length":"196","hit_length":"189","version":"Lenfried's Insane","file_md5":"de4b9a01bf44a847b7cebb96da623ccf","diff_size":"4","diff_overall":"8.5","diff_approach":"5","diff_drain":"8.5","mode":"3","submit_date":"2019-05-14 12:01:13","approved_date":"2019-05-22 15:49:35","last_update":"2019-05-22 11:51:06","artist":"antiPLUR","title":"Runengon","creator":"Raveille","creator_id":"1388767","bpm":"174","source":"osu!","tags":"featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic","genre_id":"1","language_id":"1","favourite_count":"1","rating":"0","playcount":"9","passcount":"0","max_combo":null,"diff_aim":null,"diff_speed":null,"difficultyrating":"4.318020820617676"},{"beatmapset_id":"747507","beatmap_id":"1575098","approved":"3","total_length":"199","hit_length":"183","version":"Collab Hard","file_md5":"bc4b04103cd263b039fc8349420493a7","diff_size":"3.8","diff_overall":"6","diff_approach":"7.5","diff_drain":"5","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"839","diff_aim":"1.5965542793273926","diff_speed":"1.6582205295562744","difficultyrating":"3.2856078147888184"},{"beatmapset_id":"747507","beatmap_id":"1575099","approved":"3","total_length":"199","hit_length":"182","version":"Koume's Lunatic","file_md5":"7851625279d6e841ef810ced825d8f5a","diff_size":"3.8","diff_overall":"8","diff_approach":"9","diff_drain":"5.5","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"1022","diff_aim":"2.5197982788085938","diff_speed":"2.2990376949310303","difficultyrating":"4.929216384887695"},{"beatmapset_id":"747507","beatmap_id":"1575100","approved":"3","total_length":"199","hit_length":"197","version":"Mo's Lunatic","file_md5":"9572a8b9f12005624ac623f889f5faba","diff_size":"4.2","diff_overall":"7.6","diff_approach":"8.8","diff_drain":"6","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"1108","diff_aim":"2.3829450607299805","diff_speed":"2.201321601867676","difficultyrating":"4.675078392028809"},{"beatmapset_id":"747507","beatmap_id":"1575101","approved":"3","total_length":"199","hit_length":"182","version":"Satellite","file_md5":"db69457a6d3eda63c9de4af73c556bee","diff_size":"4","diff_overall":"8.4","diff_approach":"9.2","diff_drain":"6.2","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"1138","diff_aim":"2.7451868057250977","diff_speed":"2.3703885078430176","difficultyrating":"5.302974224090576"},{"beatmapset_id":"747507","beatmap_id":"1643432","approved":"3","total_length":"199","hit_length":"183","version":"Sellenite's Normal","file_md5":"2f143083aa9bc12f94318d467a2cdd41","diff_size":"3.5","diff_overall":"4","diff_approach":"5.5","diff_drain":"4","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"584","diff_aim":"1.1335170269012451","diff_speed":"1.0233529806137085","difficultyrating":"2.211951971054077"},{"beatmapset_id":"747507","beatmap_id":"1659358","approved":"3","total_length":"199","hit_length":"173","version":"Easy","file_md5":"5ede8b76217cbf0e22980e990905181d","diff_size":"3","diff_overall":"2","diff_approach":"3","diff_drain":"2","mode":"0","submit_date":"2018-03-11 14:14:22","approved_date":"2019-05-22 16:36:04","last_update":"2019-05-21 12:48:00","artist":"senya","title":"Terasareru kurai no Shiawase","creator":"Satellite","creator_id":"1661227","bpm":"160","source":"\u6771\u65b9Project","tags":"\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei","genre_id":"1","language_id":"1","favourite_count":"11","rating":"0","playcount":"0","passcount":"0","max_combo":"483","diff_aim":"1.0374764204025269","diff_speed":"0.9278122186660767","difficultyrating":"2.020120620727539"}]
我想从所有具有相同beatmapset_id值的对象中解析所有“ difficultyrating”,并将其放入数组中。我怎样才能做到这一点?我这样做是为了仅解析JSON中的最后一个元素:
var latestBeatmap = JSON.stringify(resp[resp.length - 1]);
var parsed = JSON.parse(latestBeatmap);
答案 0 :(得分:1)
根据我在您的代码中看到的,答案似乎已经在resp
中进行了解析。字符串化并再次解析没有意义,您只需从该数组中过滤所需的值即可。
如果我的理解是正确的,那么您想获得difficultyrating
中所有beatmapset_id
您可以通过过滤器和地图来做到这一点。
例如
resp.filter(beatmap => beatmap.beatmapset_id === "971561").map(beatmap => beatmap.difficultyrating)
将产生:
["1.2615262269973755", "3.590883255004883", "2.367466926574707", "4.318020820617676"]
如果要使用最后一个节拍图,可以将数字替换为resp[resp.length - 1].beatmapset_id
resp.filter(beatmap => beatmap.beatmapset_id === resp[resp.length - 1].beatmapset_id).map(beatmap => beatmap.difficultyrating)
如果要对它们进行分组,可以像这样使用reduce:
bySetId = resp.reduce((bySetId, current) => {
if (!bySetId[current.beatmapset_id]) {
bySetId[current.beatmapset_id] = []
}
bySetId[current.beatmapset_id].push(current.difficultyrating)
return bySetId;
}, {});
bySetId将具有值:
{
747507:
[ "3.2856078147888184", "4.929216384887695", "4.675078392028809",
"5.302974224090576", "2.211951971054077", "2.020120620727539"]
971561:
[ "1.2615262269973755", "3.590883255004883", "2.367466926574707",
"4.318020820617676"]
}
然后,如果需要,您可以使用它来合并以前的值。
答案 1 :(得分:0)
var input = [{
"beatmapset_id": "971561",
"beatmap_id": "2034200",
"approved": "3",
"total_length": "196",
"hit_length": "186",
"version": "Easy",
"file_md5": "9c8eb80f6e245b5b0a0a100bbb3e274c",
"diff_size": "4",
"diff_overall": "7",
"diff_approach": "5",
"diff_drain": "7",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "1.2615262269973755"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034201",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Hard",
"file_md5": "b5fbe1a1444e35ecb7f8f03e2b61986b",
"diff_size": "4",
"diff_overall": "8",
"diff_approach": "5",
"diff_drain": "8",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "27",
"passcount": "9",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "3.590883255004883"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034202",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Normal",
"file_md5": "f7f23e1073b508593d98cb50097b0d7e",
"diff_size": "4",
"diff_overall": "7.5",
"diff_approach": "5",
"diff_drain": "7.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "2.367466926574707"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2039384",
"approved": "3",
"total_length": "196",
"hit_length": "189",
"version": "Lenfried's Insane",
"file_md5": "de4b9a01bf44a847b7cebb96da623ccf",
"diff_size": "4",
"diff_overall": "8.5",
"diff_approach": "5",
"diff_drain": "8.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "9",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "4.318020820617676"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575098",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Collab Hard",
"file_md5": "bc4b04103cd263b039fc8349420493a7",
"diff_size": "3.8",
"diff_overall": "6",
"diff_approach": "7.5",
"diff_drain": "5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "839",
"diff_aim": "1.5965542793273926",
"diff_speed": "1.6582205295562744",
"difficultyrating": "3.2856078147888184"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575099",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Koume's Lunatic",
"file_md5": "7851625279d6e841ef810ced825d8f5a",
"diff_size": "3.8",
"diff_overall": "8",
"diff_approach": "9",
"diff_drain": "5.5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1022",
"diff_aim": "2.5197982788085938",
"diff_speed": "2.2990376949310303",
"difficultyrating": "4.929216384887695"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575100",
"approved": "3",
"total_length": "199",
"hit_length": "197",
"version": "Mo's Lunatic",
"file_md5": "9572a8b9f12005624ac623f889f5faba",
"diff_size": "4.2",
"diff_overall": "7.6",
"diff_approach": "8.8",
"diff_drain": "6",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1108",
"diff_aim": "2.3829450607299805",
"diff_speed": "2.201321601867676",
"difficultyrating": "4.675078392028809"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575101",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Satellite",
"file_md5": "db69457a6d3eda63c9de4af73c556bee",
"diff_size": "4",
"diff_overall": "8.4",
"diff_approach": "9.2",
"diff_drain": "6.2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1138",
"diff_aim": "2.7451868057250977",
"diff_speed": "2.3703885078430176",
"difficultyrating": "5.302974224090576"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1643432",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Sellenite's Normal",
"file_md5": "2f143083aa9bc12f94318d467a2cdd41",
"diff_size": "3.5",
"diff_overall": "4",
"diff_approach": "5.5",
"diff_drain": "4",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "584",
"diff_aim": "1.1335170269012451",
"diff_speed": "1.0233529806137085",
"difficultyrating": "2.211951971054077"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1659358",
"approved": "3",
"total_length": "199",
"hit_length": "173",
"version": "Easy",
"file_md5": "5ede8b76217cbf0e22980e990905181d",
"diff_size": "3",
"diff_overall": "2",
"diff_approach": "3",
"diff_drain": "2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "483",
"diff_aim": "1.0374764204025269",
"diff_speed": "0.9278122186660767",
"difficultyrating": "2.020120620727539"
}];
var extract_beatmapset_id = input.map((item) => {
return {
beatmapset_id:item.beatmapset_id,
difficultyrating:item.difficultyrating
}
});
var result = {};
extract_beatmapset_id.forEach((item)=>{
if(!result[item.beatmapset_id]){
result[item.beatmapset_id] = [];
}
result[item.beatmapset_id].push(item.difficultyrating);
});
console.log(result)
您也可以在不提取代码的情况下执行代码。但是最好集中提取项目,这样我们就不会误认为其他项目(只是建议)。
答案 2 :(得分:0)
我们可以使用Set
和map
来做到这一点:
const beatMapToDifficulty = [...new Set(beatmapResp.map(b =>b.beatmapset_id))]
.map(bm => ({
beatmapset_id: bm,
difficultyratings: beatmapResp.filter(br => br.beatmapset_id === bm)
.map(b => b.difficultyrating)
}));
console.log(beatMapToDifficulty);
下面是这段代码的工作片段。
const beatmapResp = [{
"beatmapset_id": "971561",
"beatmap_id": "2034200",
"approved": "3",
"total_length": "196",
"hit_length": "186",
"version": "Easy",
"file_md5": "9c8eb80f6e245b5b0a0a100bbb3e274c",
"diff_size": "4",
"diff_overall": "7",
"diff_approach": "5",
"diff_drain": "7",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "1.2615262269973755"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034201",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Hard",
"file_md5": "b5fbe1a1444e35ecb7f8f03e2b61986b",
"diff_size": "4",
"diff_overall": "8",
"diff_approach": "5",
"diff_drain": "8",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "27",
"passcount": "9",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "3.590883255004883"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034202",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Normal",
"file_md5": "f7f23e1073b508593d98cb50097b0d7e",
"diff_size": "4",
"diff_overall": "7.5",
"diff_approach": "5",
"diff_drain": "7.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "2.367466926574707"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2039384",
"approved": "3",
"total_length": "196",
"hit_length": "189",
"version": "Lenfried's Insane",
"file_md5": "de4b9a01bf44a847b7cebb96da623ccf",
"diff_size": "4",
"diff_overall": "8.5",
"diff_approach": "5",
"diff_drain": "8.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "9",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "4.318020820617676"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575098",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Collab Hard",
"file_md5": "bc4b04103cd263b039fc8349420493a7",
"diff_size": "3.8",
"diff_overall": "6",
"diff_approach": "7.5",
"diff_drain": "5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "839",
"diff_aim": "1.5965542793273926",
"diff_speed": "1.6582205295562744",
"difficultyrating": "3.2856078147888184"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575099",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Koume's Lunatic",
"file_md5": "7851625279d6e841ef810ced825d8f5a",
"diff_size": "3.8",
"diff_overall": "8",
"diff_approach": "9",
"diff_drain": "5.5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1022",
"diff_aim": "2.5197982788085938",
"diff_speed": "2.2990376949310303",
"difficultyrating": "4.929216384887695"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575100",
"approved": "3",
"total_length": "199",
"hit_length": "197",
"version": "Mo's Lunatic",
"file_md5": "9572a8b9f12005624ac623f889f5faba",
"diff_size": "4.2",
"diff_overall": "7.6",
"diff_approach": "8.8",
"diff_drain": "6",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1108",
"diff_aim": "2.3829450607299805",
"diff_speed": "2.201321601867676",
"difficultyrating": "4.675078392028809"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575101",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Satellite",
"file_md5": "db69457a6d3eda63c9de4af73c556bee",
"diff_size": "4",
"diff_overall": "8.4",
"diff_approach": "9.2",
"diff_drain": "6.2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1138",
"diff_aim": "2.7451868057250977",
"diff_speed": "2.3703885078430176",
"difficultyrating": "5.302974224090576"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1643432",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Sellenite's Normal",
"file_md5": "2f143083aa9bc12f94318d467a2cdd41",
"diff_size": "3.5",
"diff_overall": "4",
"diff_approach": "5.5",
"diff_drain": "4",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "584",
"diff_aim": "1.1335170269012451",
"diff_speed": "1.0233529806137085",
"difficultyrating": "2.211951971054077"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1659358",
"approved": "3",
"total_length": "199",
"hit_length": "173",
"version": "Easy",
"file_md5": "5ede8b76217cbf0e22980e990905181d",
"diff_size": "3",
"diff_overall": "2",
"diff_approach": "3",
"diff_drain": "2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "483",
"diff_aim": "1.0374764204025269",
"diff_speed": "0.9278122186660767",
"difficultyrating": "2.020120620727539"
}];
const beatMapToDifficulty = [...new Set(beatmapResp.map(b =>b.beatmapset_id))]
.map(bm => ({
beatmapset_id: bm,
difficultyratings: beatmapResp.filter(br => br.beatmapset_id === bm)
.map(b => b.difficultyrating)
}));
console.log(beatMapToDifficulty);
仅获得last
难度,而不是全部:
我们使用reverse
const beatMapToDifficulty = [...new Set(beatmapResp.map(b =>b.beatmapset_id))]
.map(bm => ({
beatmapset_id: bm,
difficultyratings: beatmapResp.reverse().find(br =>
br.beatmapset_id === bm).difficultyrating
}));
这是一个有效的代码段:
const beatmapResp = [{
"beatmapset_id": "971561",
"beatmap_id": "2034200",
"approved": "3",
"total_length": "196",
"hit_length": "186",
"version": "Easy",
"file_md5": "9c8eb80f6e245b5b0a0a100bbb3e274c",
"diff_size": "4",
"diff_overall": "7",
"diff_approach": "5",
"diff_drain": "7",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "1.2615262269973755"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034201",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Hard",
"file_md5": "b5fbe1a1444e35ecb7f8f03e2b61986b",
"diff_size": "4",
"diff_overall": "8",
"diff_approach": "5",
"diff_drain": "8",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "27",
"passcount": "9",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "3.590883255004883"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2034202",
"approved": "3",
"total_length": "196",
"hit_length": "196",
"version": "Normal",
"file_md5": "f7f23e1073b508593d98cb50097b0d7e",
"diff_size": "4",
"diff_overall": "7.5",
"diff_approach": "5",
"diff_drain": "7.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "2.367466926574707"
}, {
"beatmapset_id": "971561",
"beatmap_id": "2039384",
"approved": "3",
"total_length": "196",
"hit_length": "189",
"version": "Lenfried's Insane",
"file_md5": "de4b9a01bf44a847b7cebb96da623ccf",
"diff_size": "4",
"diff_overall": "8.5",
"diff_approach": "5",
"diff_drain": "8.5",
"mode": "3",
"submit_date": "2019-05-14 12:01:13",
"approved_date": "2019-05-22 15:49:35",
"last_update": "2019-05-22 11:51:06",
"artist": "antiPLUR",
"title": "Runengon",
"creator": "Raveille",
"creator_id": "1388767",
"bpm": "174",
"source": "osu!",
"tags": "featured artist lenfried- famoss mappers' guild fa chiptune 8bit aaron dictor electronic",
"genre_id": "1",
"language_id": "1",
"favourite_count": "1",
"rating": "0",
"playcount": "9",
"passcount": "0",
"max_combo": null,
"diff_aim": null,
"diff_speed": null,
"difficultyrating": "4.318020820617676"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575098",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Collab Hard",
"file_md5": "bc4b04103cd263b039fc8349420493a7",
"diff_size": "3.8",
"diff_overall": "6",
"diff_approach": "7.5",
"diff_drain": "5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "839",
"diff_aim": "1.5965542793273926",
"diff_speed": "1.6582205295562744",
"difficultyrating": "3.2856078147888184"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575099",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Koume's Lunatic",
"file_md5": "7851625279d6e841ef810ced825d8f5a",
"diff_size": "3.8",
"diff_overall": "8",
"diff_approach": "9",
"diff_drain": "5.5",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1022",
"diff_aim": "2.5197982788085938",
"diff_speed": "2.2990376949310303",
"difficultyrating": "4.929216384887695"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575100",
"approved": "3",
"total_length": "199",
"hit_length": "197",
"version": "Mo's Lunatic",
"file_md5": "9572a8b9f12005624ac623f889f5faba",
"diff_size": "4.2",
"diff_overall": "7.6",
"diff_approach": "8.8",
"diff_drain": "6",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1108",
"diff_aim": "2.3829450607299805",
"diff_speed": "2.201321601867676",
"difficultyrating": "4.675078392028809"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1575101",
"approved": "3",
"total_length": "199",
"hit_length": "182",
"version": "Satellite",
"file_md5": "db69457a6d3eda63c9de4af73c556bee",
"diff_size": "4",
"diff_overall": "8.4",
"diff_approach": "9.2",
"diff_drain": "6.2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "1138",
"diff_aim": "2.7451868057250977",
"diff_speed": "2.3703885078430176",
"difficultyrating": "5.302974224090576"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1643432",
"approved": "3",
"total_length": "199",
"hit_length": "183",
"version": "Sellenite's Normal",
"file_md5": "2f143083aa9bc12f94318d467a2cdd41",
"diff_size": "3.5",
"diff_overall": "4",
"diff_approach": "5.5",
"diff_drain": "4",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "584",
"diff_aim": "1.1335170269012451",
"diff_speed": "1.0233529806137085",
"difficultyrating": "2.211951971054077"
}, {
"beatmapset_id": "747507",
"beatmap_id": "1659358",
"approved": "3",
"total_length": "199",
"hit_length": "173",
"version": "Easy",
"file_md5": "5ede8b76217cbf0e22980e990905181d",
"diff_size": "3",
"diff_overall": "2",
"diff_approach": "3",
"diff_drain": "2",
"mode": "0",
"submit_date": "2018-03-11 14:14:22",
"approved_date": "2019-05-22 16:36:04",
"last_update": "2019-05-21 12:48:00",
"artist": "senya",
"title": "Terasareru kurai no Shiawase",
"creator": "Satellite",
"creator_id": "1661227",
"bpm": "160",
"source": "\u6771\u65b9Project",
"tags": "\u5e7d\u9589\u30b5\u30c6\u30e9\u30a4\u30c8 touhou sellenite dailycare -mo- shirasaka_koume voyage 1969 \u6771\u65b9\u6c38\u591c\u6284 imperishable night stage 6 theme \u304b\u307e\u305b\u864e kamasetora \u795e\u5948\u68ee\u30e6\u30a6 hizumi \u96f6\u308c\u305a\u306e\u9858\u3044\u30b4\u30c8 koborezu no negai goto dagger-gazel yuuhei",
"genre_id": "1",
"language_id": "1",
"favourite_count": "11",
"rating": "0",
"playcount": "0",
"passcount": "0",
"max_combo": "483",
"diff_aim": "1.0374764204025269",
"diff_speed": "0.9278122186660767",
"difficultyrating": "2.020120620727539"
}];
const beatMapToDifficulty = [...new Set(beatmapResp.map(b =>b.beatmapset_id))]
.map(bm => ({
beatmapset_id: bm,
difficultyratings: beatmapResp.reverse()
.find(br => br.beatmapset_id === bm)
.difficultyrating
}));
console.log(beatMapToDifficulty);