Public
Edited
Feb 6, 2023
Insert cell
Insert cell
{
const tm = new Map([["key1", "value1"]]);
const t2 = new Map(tm).set("key2", "value2");
return t2;
}
Insert cell
undot = function (obj, separator) {
const undotObject = function (obj, separator = ".") {
const _undot = function (obj, parents = new Map()) {
let result = [];
if (obj) {
for (const [key, value] of Object.entries(obj)) {
const stackedKey = [...parents.keys(), key].join(separator);
if (typeof value !== "function") {
if (typeof value !== "object") {
result.push([stackedKey, value]);
} else if (Array.isArray(value)) {
continue;
} else {
for (const parentValue of parents.values()) {
if (value === parentValue) {
throw new Error("A circular reference was found");
}
}
result = result.concat(
_undot(value, new Map(parents).set(key, value))
);
}
}
}
}
return result;
};
return Object.fromEntries(_undot(obj));
};
return Array.isArray(obj)
? obj.map((i) => undotObject(i, separator))
: undotObject(obj, separator);
}
Insert cell
Insert cell
Insert cell
Insert cell
undot(undefined)
Insert cell
Insert cell
undot({})
Insert cell
Insert cell
undot(baseObject)
Insert cell
Insert cell
undot({
...baseObject,
array1: ["arrayValue1", "arrayValue2"],
array2: [{ ...baseObject }, { ...baseObject }]
})
Insert cell
Insert cell
undot({
...baseObject,
function1: function () {
return undefined;
},
function2: function () {
return undefined;
}
})
Insert cell
Insert cell
{
const symbol1 = Symbol("test symbol 1");
const symbol2 = Symbol("test symbol 2");
const testObject = { ...baseObject };
testObject[symbol1] = "symbol value 1";
testObject[symbol2] = "symbol value 2";
return undot(testObject);
}
Insert cell
Insert cell
{
const a = { ...baseObject };
const b = { ...baseObject };
b.circle = a;
a.circle = b;
return undot(a);
}
Insert cell
Insert cell
undot({
...baseObject,
subObject1: { ...baseObject, key3: "value3" },
subObject2: { ...baseObject, key3: "value4" }
})
Insert cell
undot({
...baseObject,
subObject1: { ...baseObject, key3: "value3" },
subObject2: { ...baseObject, key3: { ...baseObject, key4: "value4" } }
})
Insert cell
Insert cell
undot([{ ...baseObject }, { ...baseObject }])
Insert cell
typeof new Map()
Insert cell
new Object()[Symbol.iterator]
Insert cell
undot([1, 2, 3])
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more