JS: Array.prototype

By Xah Lee. Date: . Last updated: .

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

[see JS: Array Object]

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

Type

Type of Array.prototype is object.

[see JS: Value Types]

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

console.log (
 Object.prototype.toString.call( Array.prototype ) === "[object Array]" ) // true

console.log (
 Array.isArray ( Array.prototype ) ) // true

Parent

Parent of Array.prototype is Object.prototype.

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

[see JS: Prototype and Inheritance]

Purpose

Array.prototype is the parent of all array objects.

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

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

[see JS: Understand JS Array]

Properties

Value Properties

  1. Array.prototype.length
  2. Array.prototype.constructor

Function Properties

modify elements

  1. Array.prototype.pop
  2. Array.prototype.push
  3. Array.prototype.shift
  4. Array.prototype.unshift
  5. Array.prototype.splice
  6. Array.prototype.fill
  7. Array.prototype.copyWithin

concat and subarray

  1. Array.prototype.concat
  2. Array.prototype.slice

map

  1. Array.prototype.map
  2. Array.prototype.forEach
  3. Array.prototype.filter

sort, reverse

  1. Array.prototype.sort
  2. Array.prototype.reverse

find element

  1. Array.prototype.includes (find by value, return boolean)
  2. Array.prototype.indexOf (find by value, return index)
  3. Array.prototype.lastIndexOf
  4. Array.prototype.find (find by function, return value)
  5. Array.prototype.findIndex (find by function, return index)

true false on all elements

  1. Array.prototype.some
  2. Array.prototype.every

reduce to single value

  1. Array.prototype.reduce
  2. Array.prototype.reduceRight

convert to string

  1. Array.prototype.join
  2. Array.prototype.toString
  3. Array.prototype.toLocaleString

ES2015

  1. Array.prototype.entries
  2. Array.prototype.keys
  3. Array.prototype.values
  4. Array.prototype [ Symbol.iterator ] (same as Array.prototype.values)
  5. Array.prototype [ Symbol.unscopables ]

Note, When you see function of this form:

Array.prototype.f

you can call it by one of the following way:

[see JS: Function Call, Apply, Bind]


Array.prototype.toLocalString

myArray.toLocalString ()

ECMAScript® 2016 Language Specification#sec-array.prototype.tolocalestring

Reference

ECMAScript® 2016 Language Specification#sec-array.prototype

JS Array

  1. Understand JS Array
  2. Create Array
  3. Sparse Array
  4. Array-Like Object
  5. Array How-To
  6. Array Object
  7. Array.prototype

JS Object Reference

  1. Global
  2. Object
  3. Array
  4. Function
  5. String
  6. RegExp
  7. Date
  8. Set
  9. Map
  10. JSON
  11. Math
  12. Reflect
  13. Number
  14. Boolean
  15. Symbol
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog