Method call of the Array object in JavaScript

Source: Internet
Author: User

Method call of the Array object in JavaScript
Method concatfor loop and for in Loop

 

<Script type = text/javascript> alert (2); var arr = [,]; alert (arr); alert (length: + arr. length); var arr2 = [6, 8, 9, 5, 4]; alert (arr2); alert (arr2 [0]); alert (arr. concat (arr, arr2); for (var x in arr2) {alert (x ++ arr2 [x]);} alert (23); </script> 


 

 

Join pop shift

 

Var arr = [,]; var arr2 = [, 4]; alert (arr. join (-); alert (arr. pop (); // Delete and return the last element. If the array is empty, // This method does not change the array and returns the undefined value alert (arr. shift (); // Delete and return the first element of the array

 

Join pop shift push unshift reverse

 

Var arr = [,]; var arr2 = [, 4]; var arr3 = [0]; alert (arr. join (-); alert (arr. pop (); // Delete and return the last element. If the array is empty, // This method does not change the array and returns the undefined value alert (arr. shift (); // Delete and return the first alert element of the array (push: + arr3.push )); // 5 add one or more elements to the end of the array, and return the new array length alert (unshift + arr3.unshift (3, 2 )); // 7 add one or more elements to the beginning of the array, and return the new length of the array alert (arr3); alert (arr3.reverse (); // reverse the order of elements in the array.

 

 

Sort

 

var arr2=[6,8,50,9,5,4];alert(arr2.sort(sortNumber));function sortNumber(a,b){       return a-b}

 

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.