Skip to content Skip to sidebar Skip to footer

Filter Multi-dimension JSON Arrays

Here is the JSON details: var array={ 'app': { 'categories': { 'cat_222': { 'id': '555', 'deals': [{

Solution 1:

You can do this

var filted = _.reduce(array.app.categories, function (memo, item) {
    var result = _.filter(item.deals, function (c) {
        return c.shop.indexOf('da') != -1;
    });

    if (result.length > 0) {
        var newResult = {};
        newResult.deals = result;
        newResult.id = item.id;
        memo = _.union(memo, newResult);
    }

    return memo;
}, []);

Post a Comment for "Filter Multi-dimension JSON Arrays"