Public
Edited
May 15, 2023
Insert cell
Insert cell
Insert cell
obj = ({
foo: {
id: "foo",
label: "Foo",
description: "Long"
},
bar: {
id: "bar",
label: "Bar",
description: "Long"
},
rom: {
id: "rom",
label: "Rom",
description: "Long"
},
})
Insert cell
function stripObject(obj, remainingKeys) {
return Object.fromEntries(Object.entries(obj).map(([key, entries]) => {
return [key, Object.fromEntries(Object.entries(entries).filter(([k, e]) => remainingKeys.includes(k)))]
}))
}
Insert cell
stripObject(obj, ['label', 'id'])
Insert cell
Insert cell
arr = [{
id: "foo",
label: "Foo",
description: "Long"
}, {
id: "bar",
label: "Bar",
description: "Long" },
{
id: "rom",
label: "Rom",
description: "Long"
}]
Insert cell
function stripArray(arr, remainingKeys) {
return arr.map((d) => Object.fromEntries((remainingKeys.map(k => [k, d[k]]))));
}
Insert cell
stripArray(arr, ['id', 'label'])
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