const requests = [{
App: 'Adobe',
Count: 10
}, {
App: 'Apple',
Count: 12
}, {
App: 'Amazon',
Count: 5
}, {
App: 'Microsoft',
Count: 2
}];
requests.find(item => item.App == "Apple")
// output: {App: "Apple", Count: 12}
// find method returns actual value
requests.filter(item => item.App == "Apple")
//output: [ {App: "Apple", Count: 12} ]
// find method returns array of actual values
both usually work: the format is identical
find gets the first value that matches your criteria
filter gets all the values in the array that matches your criteria
Example
let dates = ["2022-10-17", "2022-10-18"];
for(var i in dates)
{ customDatesStyles.push({
startDate: moment(dates[i])
});
}
function change(da)
{ console.log(customDatesStyles[0].startDate);
console.log(da);
let d = customDatesStyles.find((el)=> el.startDate.format("YYYY-MM-DD") == da.format("YYYY-MM-DD")));
}
both filter and find would have been fine.
The answer with filter would just have needed to be d[0] (although there is only one in this case).
But filter can have more than one case, whereas find stops at the first found case.