mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
Co-authored-by: roesnerb <roesnerb@users.noreply.github.com> Co-authored-by: MathieuSevignyLavallee <MathieuSevignyLavallee@users.noreply.github.com>
28 lines
No EOL
607 B
JavaScript
28 lines
No EOL
607 B
JavaScript
function hasNestedValue(obj, path, delimiter = "_") {
|
|
const keys = path.split(delimiter);
|
|
let current = obj;
|
|
|
|
for (const key of keys) {
|
|
if (current && typeof current === "object") {
|
|
if (Array.isArray(current)) {
|
|
const index = current.findIndex(x => x == key)
|
|
if (index != -1) {
|
|
current = current[index];
|
|
} else {
|
|
return false;
|
|
}
|
|
} else if (key in current) {
|
|
current = current[key];
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
module.exports = { hasNestedValue}; |