@enonic/js-utils
Version:
Enonic XP JavaScript Utils
29 lines (28 loc) • 683 B
JavaScript
// object/deleteIn.ts
function deleteIn(obj, ...paths) {
if (!obj || !paths) {
return;
}
const uniformPath = [];
for (let i = 0; i < paths.length; i++) {
const path = paths[i];
if (typeof path === "string") {
path.split(".").forEach((p) => uniformPath.push(p));
} else if (Array.isArray(path)) {
path.forEach((p) => uniformPath.push(p));
} else {
uniformPath.push(path);
}
}
for (let i = 0; i < uniformPath.length - 1; i++) {
obj = obj[uniformPath[i]];
if (typeof obj === "undefined") {
return;
}
}
delete obj[uniformPath.pop()];
}
var deleteIn_default = deleteIn;
export {
deleteIn_default as default
};