Home > Article > Web Front-end > A simple js bubble sort example
This article mainly shares with you a simple js bubble sorting sample code, I hope it can help you.
<br>
rb.data是一个数组对象
//根据itemPos大小冒泡排序for(var i=0;i<rb.data.length;i++){ for(var j = 0 ;j<rb.data.length-1-i;j++){ if(rb.data[j].itemPos>rb.data[j+1].itemPos){ var temp=rb.data[j]; rb.data[j]=rb.data[j+1]; rb.data[j+1]=temp; } } }
Related recommendations:
php bubble sorting example sharing
php bubble sorting array sorting method from small to large
Detailed explanation of bubble sorting method
The above is the detailed content of A simple js bubble sort example. For more information, please follow other related articles on the PHP Chinese website!