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 = (data, test) =>
test(data)
? data
: data === Object(data)
? Object.values(data).reduce((found, n) =>
found !== null ? found : find(n, test)
, null)
: null;function find(data, test) {
for (const stack = [ data ]; stack.length;) {
const n = stack.pop();
if (test(n)) {
return n;
} else if (n instanceof Object) {
stack.push(...Object.values(n).reverse());
}
}
return null;
}const obj = find(fractal, n => n?.id === id);.