Public
Edited
May 31, 2023
2 forks
Importers
33 stars
Insert cell
Insert cell
dateMap = new Map([
[new Date(Date.UTC(2001, 0, 1)), "red"],
[new Date(Date.UTC(2001, 0, 1)), "green"] // distinct key!
])
Insert cell
dateMap.get(new Date(Date.UTC(2001, 0, 1))) // undefined!
Insert cell
Insert cell
{
const date1 = new Date(Date.UTC(2001, 0, 1));
const date2 = new Date(Date.UTC(2001, 0, 1));
return date1 === date2; // false!
}
Insert cell
Insert cell
numberMap = new Map([[978307200000, "red"]])
Insert cell
numberMap.get(978307200000)
Insert cell
numberMap.get(new Date(978307200000)) // oops!
Insert cell
Insert cell
map = new InternMap([
[new Date(Date.UTC(2001, 0, 1)), "red"],
[new Date(Date.UTC(2001, 0, 1)), "green"] // replaces previous entry
])
Insert cell
map.get(new Date(Date.UTC(2001, 0, 1)))
Insert cell
[...map.keys()]
Insert cell
Insert cell
map.get(978307200000) // this works too!
Insert cell
Insert cell
map2 = new InternMap([
[978307200000, "red"], // danger!
[new Date(Date.UTC(2001, 0, 1)), "blue"]
])
Insert cell
map2.get(new Date(Date.UTC(2001, 0, 1))) // this still works…
Insert cell
[...map2.keys()] // but the key isn’t a Date
Insert cell
Insert cell
map3 = new InternMap([
[["foo", "bar"], 1],
[["foo", "baz"], 2],
[["goo", "bee"], 3]
], JSON.stringify)
Insert cell
map3.get(["foo", "baz"])
Insert cell
Insert cell
set = new InternSet([
new Date(Date.UTC(2000, 0, 1)),
new Date(Date.UTC(2001, 0, 1)),
new Date(Date.UTC(2001, 0, 1))
])
Insert cell
InternMap = d3.InternMap
Insert cell
InternSet = d3.InternSet
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