Unit 5
List 3 Lists Practice
To do: December 13 - in your IN
What is a list in JavaScript? an array
In JavaScript, you can use an array to keep a list of elements. An array is a data structure in JavaScript used to represent a list.
Vocabulary Review
Unit 5 Lesson 3 - Warm Up
List -
Element -
Index -
an ordered collection of elements
an individual value in a list that is assigned a unique index
a common method for referencing the elements in a list or string using numbers
Using list.length-1 to access last item in array
myArray[myArray.length-1]
var myArray = [3, -4, 5, 0, 7];�var last = myArray[myArray.length-1];�console.log(last);
>>
Using list.length-1 to access last item in array
myArray[myArray.length-1]
var myArray = [3, -4, 5, 0, 7];�var last = myArray[myArray.length-1];�console.log(last);
>> 7
Go over homework
String commands
The characters in a string each have an index beginning with 0.
Example: �var city = "Houston";�console.log(city.length);�console.log(city.substring(3, 6);
H | o | u | s | t | o | n |
0 | 1 | 2 | 3 | 4 | 5 | 6 |
char
index
String commands
The characters in a string each have an index beginning with 0.
Example: �var city = "Houston";�console.log(city.length); 7�console.log(city.substring(1, 4); "ous"
H | o | u | s | t | o | n |
0 | 1 | 2 | 3 | 4 | 5 | 6 |
char
index
String commands
var name = "Debbie";
console.log(name.length);
console.log(name.substring(1,4));
console.log(name.substring(2,3));
console.log(name.substring(3,6));
console.log(name.substring(2,7));
Complete Code.org U5L03 bubbles 1-10 - pair programming
Homework