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]; }
Array Instantiation/Initialization
Computer Science and Engineering The Ohio State University
Instantiate with new
let n = new Array(3);
Initially, each element is undefined 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 = [];
Arrays are Dynamic
Computer Science and Engineering The Ohio State University
let n = [];
n
Arrays are Dynamic
Computer Science and Engineering The Ohio State University
n
n[0] = 4;
Arrays are Dynamic
Computer Science and Engineering The Ohio State University
n 04
................
................
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
- functional and object oriented javascript
- making use of built in higher order array functions in
- javascript objects and functions
- beginner s essential javascript cheat sheet
- chapter 4 javascript containers
- arrays and files
- javascript mock test iv tutorialspoint
- javascript array api
- arrays in javascript
- development environment
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