There is an exercise on Udemy where I have found this solution.
var ladders = [
{ id: 1, height: 8 },
{ id: 2, height: 10 },
{ id: 3, height: 20 },
{ id: 4, height: 25 },
{ id: 5, height: 30 },
{ id: 6, height: 40 },
];
function findWhere(array, criteria) {
return array.find(function(el) {
return el[Object.keys(criteria)] === criteria[Object.keys(criteria)];
});
}
Could you explain how the last line work? I know what the Object.keys does but I do not understand why it is between square brackets.
Thank you