Giacomo Balli profile picture
Giacomo Balli
Tech Entrepreneur | Advisor | Consultant

I help business owners navigate and leverage technology.

Let's Chat

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: Mon, 11 Jan 2016 02:55:00 +0000