I'm trying to get all objects with matching id's from my students array and get other property values from them...
For instance my array looks like this:
const students = [
{id: 1, name: 'Cal', location: 'McHale' },
{id: 2, name: 'Courtney', location: 'Sydney Hall' },
{id: 1, name: 'Cal', location: 'Syndey hall' }
]
So my expected output would grab all instances of id: 1.
{id: 1, name: 'Cal', location: 'McHale' },
{id: 1, name: 'Cal', location: 'Syndey hall' }
I'll eventually want to remove duplicate names and display in a list like so... (But that's down the line. For now I just want to grab matching objects).
Id: 1 Name: Cal Location: McHale
Syndey Hall
I've tried:
const result = _.find(students, {student_id: studentId});
But that doesn't seem to work, it just returns one of the objects with that id..
{id: 1, name: 'Cal', location: 'McHale' },
How can I make this work?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…