<script> var jsonArr = [ {id: 10, name: 'a'}, {id: 7, name: 'n'}, {id: 1, name: 'x'}, {id: 3, name: 'y'}, {id: 2, name: 'c'}, ] var arr = [1, 2, 1, 2, 34, 5, 23112, 1]; //排序數組 function sortArr(a, b) { return a - b } console.log(arr.sort(sortTest)) //找數組中的最大值 console.log(Math.max.apply(Math, arr)) //找數組中的最大值的索引 console.log(arr.indexOf(Math.max.apply(Math, arr))) //找出json數組中最大值的索引 var cur_index = 0 for (index in result) { if (result[cur_index]['id'] < result[index]['id']) { cur_index = index } } console.log(cur_index) //排序json數組 function sortJsonArr(a, b) { return a.id - b.id } result.sort(sortJsonArr); console.log(jsonArr);</script>