eoao
@eoao

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

配列内の配列で条件に一致する要素の番号を取得したい

解決したいこと

    const list = [
      [
        {name: 'バナナ', kana: 'バナナ', other: [{id:1}, {id:2}, {id:3}]},
        {name: 'apple', kana: 'リンゴ', other: [{id:4}]},
        {name: 'orange', kana: 'オレンジ', other: []},
      ],
      [
        {name: 'grape', kana: 'ブドウ'  ,other: []},
        {name: 'strawberry', kana: 'イチゴ', other: [{id:5}, {id:6}]}
      ]
    ]

上記のようなリストから、抽出したいidの値が入っている配列の要素番号を取得したいです。
例えばid=5であれば、1です。(最終的にlist[1]で値を扱いたいのです。)

お力添えよろしくお願いいたします。

自分で試したこと

条件に一致する要素の番号を取得するのにfindIndexが使用できると思い試しました。
条件がnameなどであれば以下のサイトを参考に取得できると思いましたが、
idですとfindIndex内でsome関数などを用いても、正常に要素の取得ができませんでした。

0

1Answer

Your answer might help someone💌