LoginSignup
9
5

More than 3 years have passed since last update.

JavaScriptで2次元配列のindexを取得する

Posted at

いきなりですがタイトル詐欺です。JavaScriptに多次元配列は定義されていませんが他に良い表現方法が見つからなかったのでこのような表記にしました。

サンプルコード
var hoge = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9]
];

hoge.forEach( (row, i) => {
    row.forEach( (element, j) => {
        if(element === 6) {
            console.log(i, j)  // 1,2
        }
    })
});

もうちょっとマシなタイトルがあればコメントください。

9
5
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
5