<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>

相关文章:

  • 2021-12-19
  • 2021-12-09
  • 2021-12-04
  • 2021-11-20
  • 2021-07-04
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-09
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-12-29
相关资源
相似解决方案