Suppose there is a json file with similar lines:
[ { "code":"XIY", "name":"Xianyang", "coordinates":{ "lon":108.75605, "lat":34.441154 }, "time_zone":"Asia/Shanghai", "name_translations":{ "de":"Xian Xianyang", "en":"Xianyang", "zh-CN":"西安咸阳机场", "tr":"Xi'an Xianyang Havalimanı", "ru":"Синьян", "it":"Xianyang", "fr":"Xianyang", "es":"Xianyang", "th":"ท่าอากาศยานนานาชาติซีอานเสียนหยาง" }, "country_code":"CN", "city_code":"SIA" } ] Suppose that there are many such lines. In such a json file, I need to perform a search: I want to find all the arrays in which the country_code value is equal to CN and pull the value of the name field from the appropriate search condition arrays. For such a task on the server side of my application, I use a recursive array search:
function recursive_array_search($needle,$haystack) { foreach($haystack as $key=>$value) { $current_key=$key; if($needle===$value OR (is_array($value) && recursive_array_search($needle,$value) !== false)) return $current_key; } return false; } But in this case, the search will be performed more than once when the page is loaded, but as much as the user wants and this is critical for the server’s computing resources. In this regard, I decided to shift this task to jQuery.
Question: Is it possible to perform recursive search on jQuery directly from the json string? Or does it work differently on JS?