Trying to parse through my students array to find all objects with matching ids and extract other property values from them has been challenging...
Consider the following sample array:
const students = [
{id: 1, name: 'Cal', location: 'McHale' },
{id: 2, name: 'Courtney', location: 'Sydney Hall' },
{id: 1, name: 'Cal', location: 'Syndey hall' }
]
In this scenario, the desired output would be retrieving all instances with id: 1.
{id: 1, name: 'Cal', location: 'McHale' },
{id: 1, name: 'Cal', location: 'Syndey hall' }
The end goal is to eventually eliminate duplicate names and present them in a list format like the one below... (Although that step can come later. Right now, the focus is on selecting matching objects).
Id: 1 Name: Cal Location: McHale
Syndey Hall
I have attempted using:
const result = _.find(students, {student_id: studentId});
However, this approach does not yield the desired outcome; it only retrieves one object with that specific id..
{id: 1, name: 'Cal', location: 'McHale' },
Is there a way to make this work effectively?