I have an array of objects, and I need to get list with certain property from that array of objects. But i need that list to contain only those values where object was containing another property with certain element.
This is very confusing so i made an example.
Let’s say i have an array with objects.
employees = [
{
n: 'case 1',
date: '2021-05-4',
id: '123',
user: [{name: 'Vlad', id: '1'}, {name: 'Misha', id: '2'}],
isPresent : false,
},
{
caseName: 'case 2',
date: '2021-05-4',
id: '124',
user: [{name: 'Alina', id: '3'}, {name: 'Alex', id: '4'}],
isPresent : false,
},
{
caseName: 'case 3',
date: '2021-05-4',
id: '126',
user: [],
isPresent : true,
},
]
And my task is to get a list of IDs
from array of objects, but i need ID
only from those objecrs which have isPresent
as true
.
So i need [‘123’, ‘124’].
I could use a loops and conditions and so on. But i wondering is it possible to do with one line ? Something like this:
employees.filter(item => { return item.isPresent === true }))
But i need only IDs
not whole objects.