Function similar to vlookup: Why doesn't my indexOf work?

后端 未结 1 593
刺人心
刺人心 2020-12-12 03:33

If I would like to match the word that I need to find it the same as in Excel. I intend to create a form for Example. I have a file certain big d

相关标签:
1条回答
  • 2020-12-12 03:59

    data is a 2D(two dimensional) array. indexOf only works with a 1D array. flatten the array before indexOf:

    const data = [["A1"],["A2"],["TPBSA"],["A4"]];
    console.info(data.flat().indexOf("TPBSA"));
    //or
    console.info(data.findIndex(e=>e[0]==='TPBSA'))

    0 讨论(0)
提交回复
热议问题