前提・実現したいこと
javaScriptで配列を作り、その配列から最大値を取得するプログラムを作っています。
var ary = [
[92, 90, 68, 86], //92
[78, 100, 96, 80], //100
[68, 45, 88, 75]]; //88
[92,100,88]というようにしたいのですが出力がうまくいかず、、、
3つ表示ができません。
「エラー」
SCRIPT438: Object doesn't support property or method 'push'
該当のソースコード
ソースコード function counts2() { var result = new Array(); var max1 = 0; for (i = 0; i < ary.length; i++) { for (j = 0; j < ary[i].length; j++) { if (max1 < ary[i][j]) { max1 = ary[i][j]; result = max1; result.push(ary[i][j]); } else if (max1 < ary[i][j]) { max1 = ary[i][j]; result = max1; result.push(ary[i][j]); } else if (max1 < ary[i][j]){ max1 = ary[i][j]; result = max1; result.push(ary[i][j]); } } } console.log(result); }
試したこと
console.logの位置が違うのかと場所を変えてみたり、(max1 < ary[i][j])→(max1 < ary[i])に変えて一つ一つ試してみました。(あまり関係がないかもしれませんが)
補足情報(FW/ツールのバージョンなど)
Application Insights Tools for Visual Studio
最近始めたばかりの初心者で、つたない質問ですが宜しくお願い致します。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。