Public
Edited
Oct 24, 2023
17 stars
Insert cell
Insert cell
d3.merge([[1], [2, 3]])
Insert cell
[1].concat([2, 3])
Insert cell
[[1], [2, 3]].flat()
Insert cell
Insert cell
US = new Set("qwertyuiop")
Insert cell
FR = new Set("azertyuiop")
Insert cell
d3.merge([US, FR])
Insert cell
new Set(d3.merge([US, FR])).size
Insert cell
Insert cell
[...US, ...FR]
Insert cell
new Set([...US, ...FR]).size
Insert cell
Insert cell
d3.merge(d3.cross(d3.range(10), d3.range(10), d3.range(10)))
Insert cell
Insert cell
d3.merge([[{name: "sally"}], [1, 2, 3], [function f() {}, `String`]])
Insert cell
Insert cell
d3.merge([
Float32Array.from({length: 128}, Math.random),
Float32Array.from({length: 128}, Math.random)
])
Insert cell
Insert cell
{
const input = [[1], [2, 3]];
d3.merge(input);
return input; // unchanged
}
Insert cell
Insert cell
d3.merge([[1], [2, [3]]]) // 🕷 [3] is not flattened
Insert cell
Insert cell
d3.merge([1, [2, 3]]) // 🕷 the number 1 is not iterable
Insert cell
Insert cell
Insert cell
[
0,
[1],
[2, 3],
[[4], [5]],
[[[6, 7]], [[[8]]]],
[[[[[[[[["into the abyss"]]]]]]]]]
].flat(+depth)
Insert cell
Insert cell
lyrics = [
"If my words did glow with the gold of sunshine",
"And my tunes were played on the harp unstrung",
"Would you hear my voice come through the music",
"Would you hold it near as it were your own?"
]
Insert cell
Insert cell
lyrics.flatMap(d => d.split(/\s+/))
Insert cell
Insert cell
a = Float32Array.from({length: 10}, (_, i) => -i * i)
Insert cell
b = Float32Array.from({length: 10}, (_, i) => i * i)
Insert cell
d3.merge([a, b]) // flattens typed arrays
Insert cell
[a, b].flat() // 🕷 doesn’t flatten typed arrays
Insert cell
[a, b].flatMap(d => Array.from(d)) // explicit type conversion
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more