Links
- Ref: iteration
- Arrays in JavaScript
- Arrays and Regular Expressions
- Array comprehensions
- Working with Array-like objects
- Array Methods
- Array
splice(index , howMany[, element1[, ...[, elementN]]])- Returns an array containing the removed elements. If only one element is removed, an array of one element is returned.
indexOf(searchElement[, fromIndex])- Returns the first index at which a given element can be found in the array, or -1 if it is not present.
- More arrays: Float32Array Float64Array Int16Array Int32Array Int8Array Uint16Array Uint32Array Uint8Array
Methods
concat()join(deliminator = ",")push()pop()shift()unshift()slice(start_index, upto_index)splice(index, count_to_remove, addelement1, addelement2, ...)sort()reverse()indexOf(searchElement[, fromIndex])lastIndexOf(searchElement[, fromIndex])forEach(callback[, thisObject])map(callback[, thisObject])filter(callback[, thisObject])every(callback[, thisObject])some(callback[, thisObject])
forEach
Ref: forEach()
Note: There is no way to stop or break a forEach
loop. The solution is to
use Array.every
or Array.some
(return false to break the loop.)
var colors = ['red', 'green', 'blue']; console.log(".forEach on " + colors); colors.forEach(function(value, index, arr) { console.log("a[%s] = %s", value, index); });