I have a following JsonArray:
arr = [
{
"name": "test",
"alias": "alias1",
"type": 1
},
{
"name": "test",
"type": 0
},
{
"name": "abc",
"alias": "alias2",
"type": 1
}
]
And I want to find using a variable value (which may contain alias / key). So basically the first preference of find should be alias, and if alias with the same value is not found then it should search in "name" and where "alias" is not present.
Normally it would have gone like:
_.find(arr, {
alias: value
})
But I want the code to return me the obj where name = value , if alias=value is not found
1) Ex: value = "alias1" Expected==>
{
"name": "test",
"alias": "alias1",
"type": 1
}
2) Ex: value = "test" Expected==>
{
"name": "test",
"type": 0
}