let arrayData = [
{
value: 'test',
newArray: [
{
value: 'zero',
newArray: [
{
value: 'myValue'
}
]
}
]
}
]
function find(data, val) {
const values = data instanceof Object ? Object.values(data) : [];
return values.includes(val)
? data
: values.reduce((found, n) => found || find(n, val), null);
}
const obj = find(arrayData, 'myValue');
function find(data, val) {
for (const stack = [ data ]; stack.length;) {
const n = stack.pop();
if (n instanceof Object) {
const values = Object.values(n);
if (values.includes(val)) {
return n;
}
stack.push(...values);
}
}
return null;
}