Published
Edited
Feb 15, 2019
Insert cell
Insert cell
Insert cell
Insert cell
//step 1
list1 = ['dog','cat','bird','snake']

Insert cell
//step 2
list1[2]
Insert cell
//step 3
list1.slice(0,2)
Insert cell
//step 4
list_last = {
let list_last = list1.concat('last')
return list_last
}
Insert cell
//step 4b
list1
Insert cell
//step 5
list1.length
Insert cell
//step 6
list_new = {
let list_new = list_last
list_new.splice(4,1,'new')
return list_new
}
Insert cell
Insert cell
array1=['I', 'am', 'learning','Javascript','to','munge','large','datasets','and','visualize','them']
Insert cell
Insert cell
//step 1: Convert array into a normal sentence with join()
array1.join(" ")
Insert cell
//step 2: Reverse the order of the list
array1.reverse()
Insert cell
//step 3: Sort the list using JS default sort order
array1.sort()
Insert cell
//step 4: Modify the sort to do a case insensitive alphabetic sort
array_case_insensitive = array1.sort(function(a,b) {
a = a.toLowerCase();
b = b.toLowerCase();
if (a == b) return 0;
if (a > b) return 1;
return -1;
});
Insert cell
//step 5: Show array in reverse alphabetic order
array_case_insensitive.reverse()
Insert cell
Insert cell
html`
<h3>These are my five favorite colors!</h3>
<ul>
<li style='background:forestgreen'>Forest Green</li>
<li style='background:chocolate'>Chocolate</li>
<li style='background:orange'>Orange</li>
<li style='background:goldenrod'>Goldenrod</li>
<li style='background:darkviolet'>Violet</li>
</ul>
`
Insert cell
Insert cell
md`***The current time and date is ${Date(now)}.***`
Insert cell
Insert cell
Insert cell
places_array = {
const data = {"Places":[
{'location':'South America','name':'Ushuaia','latitude':-54.805833,'longitude':-68.301947,'country':'Argentina'},
{'location':'Africa','name':'Aksum','latitude':14.132366,'longitude':38.738350,'country':'Ethiopia'},
{'location':'North America','name':'Crater Lake','latitude':42.942806,'longitude':-122.115580,'country':'United States'},
{'location':'Africa','name':'Abu Simbel','latitude':22.337222,'longitude':31.625413,'country':'Egypt'},
{'location':'Europe','name':'Alhambra','latitude':37.176534,'longitude':-3.588402,'country':'Spain'}
]};
return data;
}
Insert cell
Insert cell
function uppercaseThisArray(arrayname){
let first = arrayname.Places[0].name.toUpperCase()
let second = arrayname.Places[1].name.toUpperCase()
//return arrayname.Places[1].name.toUpperCase();
return "First: "+first+" Second: "+second;
}
Insert cell
uppercaseThisArray(places_array)
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