JS陣列遍歷和獲取陣列最值

weixin_34377065發表於2018-10-29

js中陣列模式

var myArray=new Array();

myArray = {1,4,3,7,6,9,2,5};

//獲取最大值

var max_val = '';

for (var a = 0; a < myArray.length; a++) {

var cur1 = myArray.get(a);

cur1 > max_val ? max_val = cur1 : null

}

//獲取最小值

var min_val = '';

for (var a = 0; a < myArray.length; a++) {

var cur1 = myArray.get(a);

cur1 > min_val ? min_val = cur1 : null

}

相關文章