Published
Edited
Feb 19, 2019
Insert cell
Insert cell
Insert cell
Insert cell
// 1. Create an array containing any 4 strings.
favecities = [ "San Francisco", "New York City", "Los Angeles", "New Orleans"]

Insert cell
// 2. Show the 3rd item in the list
favecities[2]

Insert cell
// 3. Show the 1st and 2nd item in the list using the slice method.
favecities.slice(0, 2)

Insert cell
// 4.Add a new string with text “last” to the end of the array and show the array.
favecities[4] = "last"
Insert cell
favecities
Insert cell
//5. Get the array length and print it.
favecities.length
Insert cell
Insert cell
favecities
Insert cell
Insert cell
array1=['I', 'am', 'learning','Javascript','to','munge','large','datasets','and','visualize','them']
Insert cell
Insert cell
// 1. Convert the array into a normal sentence with join(), then show it.
array1.join(' ')
Insert cell
// 2. Reverse the order of this list [“them”,”visualize”,…]
array1.reverse (' ')
Insert cell
// 3. Now sort the list using the default sort order in javascript
array1.sort()
Insert cell
// 4. Modify the sort to do a case insensitive alphabetic sort

array1.sort(function(a,b){
let x= a.toLowerCase(),
y= b.toLowerCase();
if (x<y) {return -1;}
if (y<x) {return 1;}
return 0;
});
Insert cell
array1.reverse()
Insert cell
Insert cell
// Your code here

html`
<h1> <span style="background:turquoise;">
Turquoise
</span> </h1>
<h1> <span style="background:Orange;">
Orange
</span></h1>
<h1> <span style="background:Green;">
Green
</span></h1>
<h1> <span style="background:Magenta;">
Magenta
</span></h1>
<h1> <span style="background:Yellow;">
Yellow
</span></h1>
`
Insert cell
Insert cell
Insert cell
Insert cell
//Creating an object listing my 5 favorite places with their respective properties.

Global = [
{Location: "San Francisco", Name:"Sutro Baths",Latitude:"122.4194° N", Longitude:"37.7749° W", Country: "United States"},
{Location:"New York City", Name: "The High Line", Latitude:"40.7128° N", Longitude:"74.0060° W", Country: "United States"},
{Location:"Berlin", Name:"Kreuzberg","Latitude":"52.5200° N", "Longitude":"13.4050° E", Country: "Germany"},
{Location:"Shanghai", Name:"Mo+ cafe ", Latitude:"a31.2304° N", Longitude:"121.4737° E", Country: "China"},
{Location:"Maputo", Name:"Polana Spa", Latitude: "25.9692° S",Longitude :"32.5732° E", Country: "China"},
]
Insert cell
Insert cell
// Creating a function that turns objects into uppercase.
toUpper = function(a){
return a.toUpperCase()
}
Insert cell
typeof(toUpper)
Insert cell
toUpper(Global[0].Name) // First Objecct Uppercase
Insert cell
toUpper(Global[1].Name)
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