Forum Discussion

alex_panganiban's avatar
alex_panganiban
Contributor
5 years ago

Getting index value from an array value

Wondering if someone could answer this question for me. Given the below array, how would I get the index number of $arrayField.name ===“Alex”?

I can easily get the index of true and false by respectively doing this: $arrayField.indexOf(true) and $arrayField.indexOf(false), but I can’t figure out how to get the index of this particular name value. I know, it’s an array of mixed datatypes and that’s what’s complicating my issue, but I need to figure out how to resolve it.

I’ve even tried “$arrayField.findIndex(x => x.name == “Alex”).” This code works as a regular Javascript expression, but SnapLogic doesn’t seem to like it as it is rejecting the “x.name”. Hope someone can help.

$arrayField = [true, {‘name’: “Alex”, “age”: 60}, false]