JavaScript: Array API
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
- push and pop in javascript example
- javascript breadth first search
- web mashups using firefox plugin vijay rao cs297 report
- javascript array api
- javascript data wrangling cheat sheet
- change array by copy for stage 2
- introducing assignment 0 a javascript crash course
- javascript immutability jfokus
- problem score points possible github pages
- ip javascript general library
Related searches
- javascript array syntax
- javascript array to string
- javascript array update existing element
- javascript array functions
- javascript array variable
- javascript array of objects example
- javascript array of objects find
- javascript array index
- javascript array index range
- javascript array index string
- javascript array splice add
- javascript array count elements