-1

How can I use the name variable in this function?

function filter(name, value) {
    return data.filter(d => d.name == value);
}

I got just an Uncaught ReferenceError: d is not defined

exotec
  • 439
  • 4
  • 17

1 Answers1

2

You can access the property of an object with the syntax object[property]. So this is the solution to your case:

function filter(name, value) {
   return data.filter(d => d[name] == value);
}
nhkhang
  • 56
  • 4