let's say I have something like this:
var SucessList = [
{
id: 1,
dedicated: true
},
{
id: 2,
dedicated: false
}
];
and I want to make an if function to check if dedicated == true. How do i select dedicated to use like that?
let res = SucessList.filter(({dedicated}) => dedicated);
({dedicated}) pattern destructures current object to set identifier dedicated to the value of the dedicated property of that object. .filter() returns the element where true is return value of callback function. If dedicated is true, the current object is returned within res array, else current object is not set as an element of resulting res array. For example let {dedicated} = { id: 1, dedicated: true }; console.log(dedicated).
SuccessList.filter(v => v.dedicated);