JavaScript 2022

Term 3 Wednesday

May - July 2022

This site will be updated live during the sessions

Week 2 Exercise 2

		
001//create an array of 3 cities
		
002let cities = ['Athens' , 'Paris', 'London'];
		
003//log to console just Paris
		
004console.log(cities[1]);
		
005//Add New York
		
006//i've used .length here to find the next index 
		
007//remember, the last index is always length -1
		
008cities[cities.length] = 'New York';
		
009//log to the console the length of the array
		
010console.log("Length after New York is added:");
		
011console.log(cities.length);
		
012cities[cities.length] = 'Tokyo';
		
013console.log("Length after Tokyo is added:");
		
014console.log(cities.length);