After learning C #, it's easy to make mistakes in JavaScript arrays

Source: Internet
Author: User
Tags javascript array

JavaScript makes it easy to make mistakes when emptying array elements:

var myarray=[];

MyArray = null; it's wrong, personally. After this assignment, MyArray will change from the array type to the string variable

Empty the array element, should myarray = [];

or myarray = new Array ();

Array declarations in javascript:

var myarray=new Array();

or Var myarray=[];

Common functions for arrays in javascript:

ToString (): Converts an array to a string
toLocaleString (): Converts an array to a string
Join (): Converts an array to a symbolic concatenated string
Shift (): Moves an element of the array head out
Unshift (): Inserts an element in the head of an array
Pop (): Deletes an element from the tail of the array
Push (): Adds an element to the tail of the array
Concat (): Adding elements to an array
Slice (): Returns the part of an array
Reverse (): Sort the array backwards
Sort (): Sort operations on an array
Splice (): Inserting, deleting, or replacing an array element

The JavaScript array does not need to be set length, it expands itself, and the array name. Length returns the number of elements

After learning C #, it's easy to make mistakes in JavaScript arrays

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.