JavaScript: Array API - Ohio State University
JavaScript: Array API
Lecture 24
Computer Science and Engineering College of Engineering The Ohio State University
Arrays: Basics
Computer Science and Engineering The Ohio State University
Numbered starting at 0 Indexed with [ ] Property length is # of elements
let sum = 0; for (let i = 0; i < n.length; i++) {
sum += n[i]; }
Iteration over elements with for...of loop
let product = 1; for (const e of n) {
product *= e }
Array Instantiation/Initialization
Computer Science and Engineering The Ohio State University
Instantiate with new
let n = new Array(3);
Initially, each element is empty Note: Elements can be a mix of types
n[0] = 10; n[1] = "hi"; n[2] = new Array(100);
Array literals usually preferred
let n = [10, 20, 30, 40]; let m = ["hi", , "world", 3.14]; [3, "hi", 17, [3, 4]].length == 4
Dynamic Size
Computer Science and Engineering The Ohio State University
Arrays can grow
let n = ["tree", 6, -2];
n.length == 3 //=> true
n[8] = 17;
n.length == 9 //=> true
Arrays can shrink
n.length = 2; // n is now ["tree", 6 ]
Arrays are Dynamic
Computer Science and Engineering The Ohio State University
let n = [];
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- sorting algorithms
- modul 5 javascript
- beginner s essential javascript cheat sheet
- searching sorting definitions of search and sort
- what is javascript
- computer operator and programming assistant 2nd semester
- e applications spring 2015 m lampis
- javascript cheat sheet edu
- chapter 15 javascript 4 objects and arrays
- javascript absolute beginner s guide
Related searches
- ohio state university degrees
- ohio state university medical center
- ohio state university holiday
- ohio state university calendar
- ohio state university academic calendar 2018
- ohio state university academic calendar
- ohio state university jobs
- ohio state university campus jobs
- ohio state university holiday calendar
- ohio state university financial statements
- the ohio state university wexner medical center
- ohio state university calendar 2020