JSFiddle - React, Tailwind, and code Playground
HTML
<div id="result"></div>
JavaScript
function customFilter(object, result, key, value){
if(object.hasOwnProperty(key) && object[key] == value)
result.push(object);
for(var i=0; i<Object.keys(object).length; i++){
if(typeof object[Object.keys(object)[i]] == "object"){
customFilter(object[Object.keys(object)[i]], result, key, value);
}
}
}
$(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 = []
customFilter(myObject, result, 'channel_id', 'dsa2');
result = result[0]
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.');
}
});