(1) How does JavaScript empty an array?
Such as
var arrayList = [' A ', ' B ', ' C ', ' d ', ' e ', ' F '];
How to EmptyarrayList
Method 1: Directly change the object that the ArrayList points to, the original object does not change.
ArrayList = [];
Method 2: This method clears the original array by setting the length=0 element.
arraylist.length = 0;
Method 3
Arraylist.splice (0, arraylist.length);
(2) How can I tell if an object is an array? Method 1: Use Object.prototype.toString to determine if it is an array, and call is used here to point the this in toString to obj. And then complete judgment.
function IsArray (obj) { return Object.prototype.toString.call (obj) = = = ' [Object Array] ';}
Method Two: Using the prototype chain to complete the judgment, the basic idea is to use an instance if it is constructed by a constructor, then its
__proto__
is a pointer to the constructor
prototype
Property.
function IsArray (obj) { return obj.__proto__ = = = Array.prototype;}
Method 3: Use jquery
function IsArray (obj) { return $.isarray (obj)}
javascript--face question