I have this array here (stressValues):
[ { angeredoutsidecontrol: 1 }, { difficultiespileup: 2 } ]
I'd like to find the array index value based on the property name of one of the contained objects, such as angeredoutsidecontrol, which would return 0
How can I achieve this?
This is what I have so far:
for(const value of values) {
const stressValue = Object.values(value)[0];
const valueName = Object.keys(value)[0];
for (const name in stressValues) {
if (name === valueName) {
console.log(name);
console.log(values.indexOf(name)); // trying to get it to return 0
}
}
}
arr.map((e, i) => {e.index = i; return e})