var cars = ["Saab", "Volvo", "BMW"]; //Array var cars2 = {"Saab", "Volvo", "BMW"}; //Object 要讀取 BMW 時:Array : cars [0] ,Object : cars2["BMW"]
Array常用方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
pop() //移除最後一個item,並return它 var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.pop(); // Removes the last element ("Mango") from fruits push(item) //把item加在最後面,return 新的Length回來 var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi"); //Adds a new element ("Kiwi") to fruits shift() //移除第一個並回傳 unshift() //把item加在最前面,回傳length sort() //可依照字母排序 reverse() //依照字母倒排