javascript--face question

Source: Internet
Author: User

(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 prototypeProperty.
function IsArray (obj) {    return obj.__proto__ = = = Array.prototype;}
Method 3: Use jquery
function IsArray (obj) {    return  $.isarray (obj)}

javascript--face question

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.