Is there a way to find the index of two keys with specific values in an object?
let myObj = {
"value1":[1,2,3],
"value2":[2,3,4]};
I am trying to locate the index when
myObj.value1==1 && myObj.value2==2
, but I can't figure it out.
edit : perhaps this could work:
if (myObj.value1.indexOf(1) == myObj.value2.indexOf(2)) {
commonIndex = myObj.value1.indexOf(2);}
However, is there a more elegant solution?
Also, how should I handle cases where the value occurs multiple times?
for example :
let myObj = {
"value1":[1,1,1,2,3,4,5],
"value2":[2,3,4,5,6,7,8]}
In this scenario, how can I find the index when value1==1
and value2==3
.