Published
Edited
Nov 3, 2020
Importers
Insert cell
Insert cell
function pivot_shorter(data, ...properties) {
const shortData = properties.reduce((a, b) => ((a[b] = ''), a), {});

for (const [key, value] of Object.entries(shortData)) {
shortData[key] = data.map(item => item[key]);
}

return shortData;
}
Insert cell
Insert cell
beers
Insert cell
pivot_shorter(beers, "abv", "ibu", "ph") // Specify which properties to keep
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