I have an array
0: key: "001" value: Array(1) 0: Id: "2345" Name: "Test"
1: key: "112" value: Array(2) 0: Id: "1234" Name: "UHV" 1: Id: "3424" Name: "ABC"
2: key: "222" value: Array(3) 0: Id: "2312" Name: "ABD" 1: Id: "1321" Name: "RFV" 2: Id: "4567" Name: "ERF"
when i try to Search with ‘AB’ my logic should search my array object and return . please help me for the logic
1: key: "112" value: Array(1) 0: Id: "3424" Name: "ABC"
2: key: "222" value: Array(1) 0: Id: "2312" Name: "ABD"
3
Answers
First you given JSON Array is wrong. I corrected it based on assumption:
Secondly, you can achieve this via using Array
some()
Refer to the below code for reference:
You can use
Array::filter()
to findAB
Name invalue
withString::includes()
and compose the root filtered array withArray::reduce()
. The filteredvalue
array items are composed with spread and destructuring syntax:here are three simple examples of how you can filter the array based on your criteria