Find the second largest number in array
问题 I have an array of three element like [31,23,12] and I want to find the second largest element and its related position without rearranging the array . Example : array = [21,23,34] Second_largest = 23; Position is = 1; 回答1: Make a clone of your original array using .slice(0) like : var temp_arr = arr.slice(0); Then sor it so you get the second largest value at the index temp_arr.length - 2 of your array : temp_arr.sort()[temp_arr.length - 2] Now you could use indexOf() function to get the