var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits = fruits.sort();
document.write(fruits);
for(var i = 0; i < Math.ceil(fruits.length / 2); i++) {
var temp = fruits[i];
fruits[i] = fruits[fruits.length - 1 - i];
fruits[fruits.length - 1 - i] = temp;
}
document.write(fruits);
我试图反转有序(a-z)数组,以便在for循环中使其成为z-a。为什么这不起作用?