一只甜甜圈
尝试这个: const finalResult = {}; const data = { "data": [ { "persons": { "Dupont nicolas": "President", "George frimaolo": "engineer", "Tiprana masilo": "football player" } }, { "persons": { "Balack martini": "author", "Dupont nicolas": "Student", "Joseph Allen": "dentist" } }, { "persons": { "Fred Samanta": "baker", "Romero flagipi": "actor", "Fred Samanta": "astronaut", "Joseph Allen": "pilot", "Anne Hedley": "teacher" } } ] } for (let i in data.data) { for (let j in data.data[i].persons) { finalResult[j] = finalResult[j] ? finalResult[j] : data.data[i].persons[j]; } } console.log(finalResult);
不负相思意
使用reduce和Object.assignconst combine = (arr) => arr.reduce((acc, { persons }) => Object.assign(acc, persons), {});const data = [ { persons: { "Dupont nicolas": "President", "George frimaolo": "engineer", "Tiprana masilo": "football player", }, }, { persons: { "Balack martini": "author", "Dupont nicolas": "Student", "Joseph Allen": "dentist", }, }, { persons: { "Fred Samanta": "baker", "Romero flagipi": "actor", "Fred Samanta": "astronaut", "Joseph Allen": "pilot", "Anne Hedley": "teacher", }, },];console.log(combine(data))