JavaScript: Array.prototype

By Xah Lee. Date: . Last updated: .

Array.prototype is the value of the property key "prototype" of the function Array.

[see Array Object]

console.log( Array.hasOwnProperty ( "prototype" ) ); // true

Type

Type of Array.prototype is Object .

console.log( typeof Array.prototype === "object" ); // true

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 ) ); // true

console.log( Array.prototype.length === 0); // true

Array.prototype.push ( "a", "b" );

console.log( Array.prototype ); // [ 'a', 'b' ]

console.log( Array.prototype.length === 2 ); // true

Parent

Parent of Array.prototype is Object.prototype .

// parent of Array.prototype
console.log( 
 Reflect.getPrototypeOf ( Array.prototype ) === Object.prototype
); // true

Purpose

Array.prototype is the parent of all array objects.

console.log( 
Reflect.getPrototypeOf ( [3,4,5] ) === Array.prototype
); // true

Purpose of Array.prototype is to provide methods and properties useful for all array objects

[see Understand JS Array]

Properties

Value Properties

Function Properties

modify elements

concat and subarray

get elements

map

sort, reverse

find element

true false on all

reduce to single value

convert to string

flatten

JavaScript Array

∑ JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Array

prototype