Platform
Resources
Pricing
Sign in
Get started
Ashley Suh
Tech Staff @ MIT Lincoln Lab, with a focus on visual analytics, information visualization, and human-centered AI.
Workspace
Fork
Public
By
Ashley Suh
Edited
Nov 18, 2022
1
Insert cell
Insert cell
Insert cell
example_data
=
FileAttachment
(
"example.csv"
)
.
csv
(
{
typed
:
true
}
)
Insert cell
Insert cell
Inputs
.
table
(
example_data
)
Insert cell
Insert cell
// Just an example of how JavaScript iterates over arrays with built-in functions
// Open up the console and see what's happening
example_data
.
forEach
(
(
d
,
i
)
=>
{
// d is the *entire* data element being iterated on currently
// i is the index of the current element
console
.
log
(
"d is: "
,
d
,
" & i is: "
,
i
)
;
// check if the data element is Florida
if
(
d
.
State
===
"Florida"
)
{
console
.
log
(
"It's Florida! See?: "
,
d
.
State
)
;
}
}
)
Insert cell
Insert cell
// I'm creating a new array, all_states, that "maps" the original array
// and modifies the element to be just the State names instead of the State, Value pairs
// Now it's just an array of strings (State names) instead of objects
all_states
=
example_data
.
map
(
d
=>
d
.
State
)
;
Insert cell
// Notice that even though I use an if-statement to check if the state is
// Florida, it will still fill the array with undefineds because no matter what,
// map() will return an array with the same number of elements as the original array
only_florida_states_shown
=
example_data
.
map
(
d
=>
{
if
(
d
.
State
===
"Florida"
)
{
return
d
.
State
;
}
}
)
;
Insert cell
Insert cell
actually_only_florida_states
=
example_data
.
filter
(
d
=>
{
return
d
.
State
===
"Florida"
}
)
Insert cell
Insert cell
example_data
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
example_data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
all_states
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
only_florida_states_shown
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
actually_only_florida_states
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML