Kris Wood
06/05/2020, 5:16 PMSandii
06/05/2020, 5:27 PMKris Wood
06/05/2020, 5:28 PMKris Wood
06/05/2020, 5:28 PMSandii
06/05/2020, 5:28 PMKris Wood
06/05/2020, 5:29 PMKris Wood
06/05/2020, 5:29 PMSandii
06/05/2020, 5:30 PMSandii
06/05/2020, 5:30 PMvar testValue = 'x';
var testProperty = 'y';
objectArr.map(function (entry, index){
if (entry[testProperty] == testValue){
return index;
}
});
Kris Wood
06/05/2020, 5:31 PMKris Wood
06/05/2020, 5:32 PMKris Wood
06/05/2020, 5:32 PMKris Wood
06/05/2020, 5:33 PMSandii
06/05/2020, 5:33 PMundefined
Sandii
06/05/2020, 5:33 PMlet testArr = [
{name: 'a'}, {name: 'a'}, {}
]
testArr.map(function (entry, index){
if (entry.name == 'a')
return index;
})
//results
Ā [0, 1, undefined]
Kris Wood
06/05/2020, 5:33 PMstalbert
06/05/2020, 5:55 PMSandii
06/05/2020, 5:56 PMstalbert
06/05/2020, 5:58 PMKris Wood
06/05/2020, 5:59 PMstalbert
06/05/2020, 5:59 PMKris Wood
06/05/2020, 5:59 PMKris Wood
06/05/2020, 6:00 PMstalbert
06/05/2020, 6:00 PMKris Wood
06/05/2020, 6:01 PMKris Wood
06/05/2020, 6:03 PMundefined
just like you saidKris Wood
06/05/2020, 6:03 PMstalbert
06/05/2020, 6:03 PM