Array
1. What is an Array?
A collection of values (elements) with order (index)
2. Array Syntax
Order starts from 0, not 1
Use square brackets
[]to create an arraySeparate each element with a comma
,
3. Array Index Finding/Adding/Deleting
Getting Index Values
let myNumber = [73, 98, 86, 61, 96];
// What is the value at the 3rd index of the myNumber array?
myNumber[3]; // 61
let myNumber = [73, 98, 86, 61, 96];
// What is the value at the 5th index of the myNumber array?
myNumber[5]; // undefined: this array only has values up to the 4th indexGetting Index Values from Arrays Inside Arrays
Finding Array Length
Adding/deleting elements at the end of an array
You can execute related commands (methods) using dot notation (.)
When executing commands, you can run them in the form of opening and closing parentheses like calling a function
4. Array Iteration
Using Loops to Print Each Element of an Array
Adding All Elements of an Array Cumulatively
If you don't assign 0 initially, undefined will be returned, and if you continue the calculation below without an initial value, NaN will result.
5. Object Value Lookup Methods
Array.isArray
Determining whether a specific value is an array or not
push, pop
Adding or deleting elements of an array
indexOf
Checking if a specific value is included in an array and finding its index value
includes
Checking if a specific value is included in an array
Last updated