☞ Need help? I have an open spot for consulting in my schedule. Hire me.

Find match in JSON Object

This code sample will allow you to look through an array of JSON objects and extract a specific property.

function findInJSON(el, key, id, toReturn) {
    for (var q = 0; q < el.length; q++) {
        if (el[q][key] == id) {
            return el[q][toReturn];
    return false;

- call findInJSON(el, key, id, toReturn);
- el is the array of JSON objects
- key is the property to be used when searching
- id is the value you are searching for
- toReturn is the property you want to be returned from the matching object

This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes.

Back to main listing.