Giacomo Balli profile picture
Giacomo Balli
Your Technology Advisor

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

Let's Chat 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