JSFiddle - React, Tailwind, and code Playground

by Rafa Ola

HTML

<div id="result"></div>
http://jsfiddle.net/follypimpz/FM3qu/629/

JavaScript

function getObject(theObject) {
  var result = null;
  if (theObject instanceof Array) {
    for (var i = 0; i < theObject.length; i++) {
      result = getObject(theObject[i]);
    }
  } else {
    for (var prop in theObject) {
      console.log(prop + ': ' + theObject[prop]);
      if (prop == 'id') {
        if (theObject[prop] == 1) {
          return theObject;
        }
      }
      if (theObject[prop] instanceof Object || theObject[prop] instanceof Array)
        result = getObject(theObject[prop]);
    }
  }
  return result;
}

$(function() {
  var myObject = [{
    'title': 'some title',
    'channel_id': '123we',
    'options': [{
      'channel_id': 'abc',
      'image': 'http://asdasd.com/all-inclusive-block-img.jpg',
      'title': 'All-Inclusive',
      'options': [{
        'channel_id': 'dsa2',
        'title': 'Some Recommends',
        'options': {
          'image': 'http://www.asdasd.com',
          'title': 'Sandals',
          'id': '2'
        }
      }, {
        'channel_id': 'dsa3',
        'title': 'Some Recommends',
        'options': {
          'image': 'http://www.badasd.com',
          'title': 'Boots',
          'id': '1'
        }
      }]
    }]
  }];

  var result = getObject(myObject);

  if (result != null) {
    $('#result').html('Found object: <br />');
    for (var prop in result) {
      $('#result').html($('#result').html() + prop + ': ' + result[prop] + '<br />');
    }
  } else {
    $('#result').html('Not Found.');
  }
});