An array is an ordered lists of values
var arr = [];arr is the name of the variable.
"array" is a keyword.
var stands for?
[ ] are the array literal.
Bonus: Is [ ] truthy or falsy?
var arr = [];Yes. It's that simple.
var arr = new Array();Alternate: FYI
Make an Array that contains the following:
Make an Array that contains 3 more arrays.
var matrix = [
[1,2,3],
[4,5,6],
[7,8,9]
];Values are accessed by their index.
An index is the value's position in the array.
⬜️ What number does an array's index begin at?
var books = ["Harry Potter",
"Wheel of Time",
"Lord of the Rings"
];
books[0]
// "Harry Potter"Bracket notation is how you access particular values in an array.
var movies = ["Iron Man", "Titanic", "Up"];⬜️ Write proper notation to access "Up"
"delete" is the keyword to delete a value from an array. You use bracket notation to point to which value you wish to delete
var movies = ["Iron Man", "Titanic", "Up"];
delete movies[1];
console.log(movies[1]);
⬜️ What will be returned?
var movies = ["Iron Man", "Titanic", "Up"];
Arrays have length!
movies.length
// 3
.indexOf() method behaves like a search and returns that the index of the item in parentheses
movies.indexOf("Titanic");
// 1
[] == [] // false
[] === [] // falseCan you compare arrays using "==" or "==="?
You must compare values IN the array, not the arrays themselves.
They have the same preferred name so they're the same right?
liable for change or alteration
var a = [1,2,3];
var b = a;
console.log(b);
// [1,2,3]
a[0] = 44;
console.log(b);
// ?🖐 What is an array?
⬜️ What is the syntax of an array?
🖐 What is an index?
⬜️ How would you access "orange"?
var colors = ["blue", "orange", "pink", "yellow"];⬜️ How would you access "black"?
var colors = [
["blue", "orange", "pink", "yellow"],
["purple", "red", "white"],
["black", "green", "indigo"]
];🖐 What happens when you use the keyword delete for an array value?
.length
.pop()
.push()
.indexOf()
.shift()
.unshift()
.splice()
.slice()
.sort()
.reverse()
.join()
.concat()
🖐What is a destructive method?
🖐Can you compare arrays? Why?
🖐What does mutable mean?