var fractal = var fractal = {
"152": {
"99": {
"465": [
{
"id": 295,
"webmaster_id": 99,
"invoice_id": null,
"stream_id": 465,
"created_at": "2022-02-09 00:44",
"section": "reg",
"commission": "30.00",
"status": "В обработке",
"comment": "",
"order": {
"id": 152,
"name": "TEST",
}
},
{
"id": 105,
"webmaster_id": 99,
"invoice_id": null,
"stream_id": 465,
"created_at": "2022-02-03 23:37",
"section": "reg",
"commission": "30.00",
"status": "В обработке",
"comment": "",
"order": {
"id": 152,
"name": "TEST",
}
},
{
"id": 172,
"webmaster_id": 99,
"invoice_id": null,
"stream_id": 465,
"created_at": "2022-02-03 17:32",
"section": "reg",
"hit_group": "",
"commission": "30.00",
"status": "В обработке",
"comment": "",
},
{
"id": 260,
"webmaster_id": 99,
"invoice_id": null,
"stream_id": 465,
"created_at": "2022-02-03 00:46",
"section": "reg",
"commission": "30.00",
"status": "В обработке",
"comment": "",
}
],
},
"1166": {
"400": [
{
"id": 275,
"webmaster_id": 1166,
"invoice_id": null,
"stream_id": 400,
"created_at": "2022-02-05 00:50",
"section": "reg",
"commission": "1.00",
"status": "В обработке",
"comment": "",
}
]
}
}
}
order": {
"id": 152,
"name": "TEST",
}
let id = 152;
getFiniteValue(fractal);
function getFiniteValue(obj) {
getProp(obj);
function getProp(o) {
for(var prop in o) {
if(typeof(o[prop]) === 'object') {
getProp(o[prop]);
} else {
if(id = o[prop]) {
console.log(o[prop])
}
}
}
}
}
const find = (obj, key, val) =>
obj instanceof Object
? obj[key] === val
? obj
: Object.values(obj).reduce((found, n) => found ?? find(n, key, val), null)
: null;
const obj = find(fractal, 'id', id);
function find(obj, key, val) {
for (const stack = [ obj ]; stack.length;) {
const n = stack.pop();
if (n instanceof Object) {
if (n[key] === val) {
return n;
}
stack.push(...Object.values(n));
}
}
return null;
}