Let\'s say I have an object:
[
{
\'title\': \"some title\"
\'channel_id\':\'123we\'
\'options\': [
{
I would try not to reinvent the wheel. We use object-scan for all our data processing needs. It's conceptually very simple, but allows for a lot of cool stuff. Here is how you would solve your specific question
const objectScan = require('object-scan');
const find = (id, input) => objectScan(['**'], {
abort: true,
rtn: 'value',
filterFn: ({ value }) => value.id === id
})(input);
const data = [{
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: '1',
content: {}
}]
}]
}]
}];
console.log(find('1', data));
// => { image: 'http://www.asdasd.com', title: 'Sandals', id: '1', content: {} }