<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>