I have the following function which takes a dataset, field name and search string then uses ES2015's arrow functions to find the result.
Example call is:
var whatever = myDataSet.find(entry => entry.name === 'John');
I need to build this from arguments within a function but I cannot get the field name in.
The function:
findSingle: function(dataSet, fieldName, searchString){
return dataSet.find(entry => entry.fieldName === searchString);
}
Which I'd call with:
my.nameSpace.findSingle(dataSetName, 'name', 'John');
And I expect it to then call:
dataSetName.find(entry => entry.name=== 'john');
But it fails. (If I hard code entry.name
it work as expected) I'm pretty sure it's because I'm passing a string to be an object property for entry.name
but I can't think of another way to do this.
Is it possible to pass strings into object properties like this or should I do it a different way?