var pos = fruits.indexOf("banana"); // 1 // 如果找不到该元素,则返回 -1
通过索引删除某个元素
1 2
var removeItem = fruits.splice(pos, 1); // this is how to remove an item // ["Strawberry", "Mango"]
复制一个数组
1 2
var shallowCopy = fruits.slice(); // this is how to make a copy // ["Strawberry", "Mango"]
将数组中的所有元素连结为一个字符串
1 2 3 4 5 6 7 8 9 10 11 12
var str = fruits.join(''); // StrawberryMango
fruits.toString(); // Strawberry,Mango
var number = 1337; var date = newDate(); var myArr = [number, date, "foo"]; var str = myArr.toLocaleString(); console.log(str); // 1337,2016/9/29 下午6:07:07,foo