Hacker News new | past | comments | ask | show | jobs | submit login

added this to the post as well, a place where there is an array inside an array of objects and you want all those. For example, if we want to extract all roles from the array:

[ { name: "Saransh Kataria" , roles: ['system-admin', 'developer'] }, { name: "Wisdom Geek" , roles: ['basic'] }, ].flatMap(x => x.roles);

// Output => ["admin", "system-admin", "developer"]




wouldn't the output be ['basic', 'system-admin', 'developer'] rather than array[0] being 'admin'?


You are right that it should be 'basic', not 'admin'. But the order should be 'system-admin', 'developer', and finally 'basic'.


you are right, I was trying to format it for HN but somehow screwed up copy pasting, though it'd be ["system-admin", "developer", "basic"] and not ['basic', 'system-admin', 'developer']




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: