I have a json object like shown below which contains id-to name mappings:
idToNamesMap = {"1":"name5","2":"name6","3":"name7","4":"name8"}
Now I want to search for names in this id-to name mappings object. For example search & return all names starting with string “name” along with corresponding ids. Could you suggest how to do this ?
I use jQuery 1.7.
If I understand you correctly you want to filter the items starting with
"name"and then flip the object keys / values:Output:
See also:
jQuery.each()