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
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
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);
}