js array對象方法

<pre name="code" class="html">function myFunction()
{
var points = [40,100,1,5,25,10];
points.sort(function(a,b){
	alert(a+"---"+b)
	return a-b});
var x=document.getElementById("demo");
x.innerHTML=points;
}
原理是a-b 正數的話位置不變,非正數位置互換
然後和最大的比較。
分別是:40 100,100 1,40 1,100 5,40 5,100 5,1 5 ,100 5 ,40 25,5 25 ,100 10,40 10,25 10,5 10,

</pre><p>js array對象方法</p><p>concat 連接方法</p><p>indexof 檢索位置方法</p><pre name="code" class="html"><!DOCTYPE html><html><body><p id="demo">Click the button to display the position of the element "Apple":</p><button οnclick="myFunction()">Try it</button><script>function myFunction(){var fruits = ["a","b","c","d","c","b","a","d","f","a","c"];var a = fruits.indexOf("a",7) // 從第七位開始檢索,找a出現的位置,出9var x=document.getElementById("demo");x.innerHTML=a;}</script></body></html>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章