I have an array structured like the following and I'm looking to retrieve all values where the description matches a given value. I understand how to retrieve the first array value where the condition is met, but I'm unsure of how to retrieve all values where the description equals the given one.
[
Discovery {
name: 'Lorem ipsum',
description: 'lorem ipsum',
date: 2019-12-15T22:03:17.078Z,
url: 'https://loremipsum.io/',
discoveryId: 1,
userId: 1
},
Discovery {
name: 'Lorem ipsum2',
description: 'bbbbbbb',
date: 2019-12-15T22:03:17.079Z,
url: 'https://loremipsum.io/',
discoveryId: 2,
userId: 2
},
Discovery {
name: 'Lorem ipsum3',
description: 'bbbbbbb',
date: 2019-12-15T22:03:17.079Z,
url: 'https://loremipsum.io/',
discoveryId: 3,
userId: 3
}
]
This is where the array originates
let nextId;
const discoveryList = [];
class Discovery{
constructor(name, description, date, url, discoveryId, userId){
this.name = name;
this.description = description;
this.date = date;
this.url = url;
this.discoveryId = discoveryId;
this.userId = userId;
}
static addDiscovery(discovery, userId){
discovery.discoveryId = nextId++;
discovery.userId = userId;
discoveryList.push(discovery);
return discovery;
}
static discoveryList(){
return discoveryList;
}
}