Last active
November 26, 2020 15:07
-
-
Save revox/75894b97d79cde12e2d0 to your computer and use it in GitHub Desktop.
Exercise 1 - Starting code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Test page</title> | |
</head> | |
<body> | |
<p> | |
Use the force Luke...(or the console 'View->Developer Tools->JavaScript Console') | |
JSON? <a href = "https://www.w3schools.com/js/js_json_syntax.asp">erm...</a> | |
</p> | |
<script type="text/javascript"> | |
// an array of objects | |
var employees = [ | |
{"firstName":"John", "lastName":"Lennon"}, | |
{"firstName":"Paul", "lastName":"McCartney"}, | |
{"firstName":"Ringo","lastName": "Star"} | |
]; | |
// print out the entire array, you'll see the arrowi the console, click it to drill down into the object | |
console.log(employees); | |
// print out the first element of the array, the console shows and object with an arrow | |
console.log(employees[0]); | |
// print out the value for the key lastName in the first element of the list using dot notation | |
console.log(employees[0].lastName); | |
// as above but using associative array notation | |
console.log(employees[0]['lastName']); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment