JavaScript: Array.prototype
Array.prototype
is the value of the property key "prototype"
of the function Array
. [see Array Object]
console.log( Array.hasOwnProperty ( "prototype" ) );
Type
Type of Array.prototype
is Object
.
console.log( typeof Array.prototype === "object" );
Array.prototype
is a true array. Meaning, you can push elements to it, and with a magical length
property.
console.log( Array.isArray ( Array.prototype ) ); console.log( Array.prototype.length === 0); Array.prototype.push ( "a", "b" ); console.log( Array.prototype ); // [ 'a', 'b' ] console.log( Array.prototype.length === 2 );
Parent
Parent of Array.prototype
is Object.prototype
.
// parent of Array.prototype console.log( Reflect.getPrototypeOf ( Array.prototype ) === Object.prototype );
Purpose
Array.prototype
is the parent of all array objects.
console.log( Reflect.getPrototypeOf ( [3,4,5] ) === Array.prototype );
Purpose of Array.prototype
is to provide methods and properties useful for all array objects
[see Understand JS Array]
Properties
Value Properties
- length
- constructor
- [Symbol.iterator]
- [Symbol.unscopables]
Function Properties
modify elements
concat and subarray
get elements
map
sort, reverse
find element
- includes (find by value, return boolean)
- indexOf (find by value, return index)
- lastIndexOf
- find (find by function, return value)
- findIndex (find by function, return index)
true false on all
reduce to single value
convert to string
[ Symbol.unscopables ]
flatten