Giacomo Balli profile picture
Giacomo Balli
The Mobile Guy

Over two decades of experience at your service.
I help business owners make better decisions.

Free 20-Minute Consultation LinkedIn

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;
}

Directions:
- 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

Note:
This snippet focuses on iOS development. Make sure to verify/adapt any vendor prefixes. Back to main listing.

Published: Sun, Jan 10 2016 @ 18:55:00
Back to Blog