Public
Edited
Oct 20, 2024
Insert cell
Insert cell
Insert cell
cities = raw
//split text into array at new lines
.split("\n")
//split each row at tab characters
.map((d) => d.split("\t"))
//create a new array for each row
.map((d) => [
//beginning with its name which got split away by the tab split
d[0],
//and then add on the rest of the row
...d[1]
//having split at spaces
.split(" ")
//removed any empty strings
.filter((e) => e)
//and converted to float the lng/lat and int everything else
.map((e, i) => (i == 10 || i == 11 ? parseFloat(e) : parseInt(e)))
])
//convert each array to a JSON object
.map((d) =>
d.reduce((a, v, i) => {
a[headers[i]] = v;
return a;
}, {})
)
Insert cell
Insert cell
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