Length of JS Array (JavaScript tutorial IV)

Source: Internet
Author: User

This is a simple function that uses length to judge an array and iterate over an array.

<script language= "Web Effects" type= "Text/javascript" >
<!--
function Bubblesort (arr) {
Outer Loop, total arr.length for maximum operation
for (Var i=0;i<arr.length;i++) {
Inner Loop, find the first-largest element and exchange it with the first element
for (Var j=i;j<arr.length;j++) {
if (Arr[i]<arr[j]) {
Swap position of two elements
var temp=arr[i];
ARR[I]=ARR[J];
Arr[j]=temp;
}
}
}
}

var arr=[32,55,78,43,78,10,45,20,9,89];
Bubblesort (arr);

Output: 89,78,78,55,45,43,32,20,10,9
for (Var i=0;i<arr.length;i++) {
document.write (arr[i]+ ",");
}
-->
</script>

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.