I have a method that looks like this:
retrieveUniqueValues(param) {
var uniqueValues = [];
uniqueValues = this.state.DataObjects.map(item => {
if (uniqueValues.indexOf(item[param]) === -1) {
uniqueValues.push(item[param])
}
});
}
//DataObjects is an array of objects
DataObjects = [
{tag: 23, name: vicky, gender: m},
{tag: 13, name: sam, gender: m},
{tag: 23, name: raj, gender: m}
]
//item can be any object as shown above
item = {tag: 23, name: vicky, gender: m}
The param here represents the property name such as tag.
Even though the param has a value before and after the map function, I am encountering it as undefined in the following line:
if (uniqueValues.indexOf(item[param]) === -1) { }
My goal is to retrieve unique values for any specific property, for example, for the tag: 23, 13. While using x.tag or x.name or x.gender works fine, I intend to make the property name dynamic.