How much do you know about arrays

  array, Front end, javascript

Links to blog articles:How much do you know about arrays

Judge whether a variable is an array.

Method for reliably detecting array

1. UtilizationObjectThetoStringMethod

var list = [1, 2, 3];
Object.prototype.toString.call(list);//[object Array]

2. UtilizationES5TheArray.isArray()Method

var list = [1, 2, 3];
Array.isArray(list);//true

What are the native methods of arrays?

Will change their own way:

  • copyWithinfillpoppushreverseshiftsortspliceunshift

Will not change its own method:

  • concatincludesjoinslicetoSourcetoStringindexOflastIndexOf

Traversal method:

  • forEachentrieseverysomefilterfindfindIndex
  • keysmapreducereduceRightvalues

How to convert variables of class array into array?

  • If it isES6You can use theArray.from()Methods.
  • Usually usedArray.prototype.slice.call()Method to convert a similar array to an array.