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

强颜欢笑 提交于 2020-12-21 04:11:39

问题


If I would like to match the word that I need to find it the same as <lookup> in Excel. I intend to create a form for Example. I have a file certain big data and I will create a box for fill in data that you need then Enter it show the Description of data. Now I got stuck I don't know how to write to the script I have learned in youtube but don't have a solution that nearby with my need it nearby just <Indexof> function.

 var data = Activesheet.getRange(1,1,Activesheet.getLastRow()-1,1).getValues();
 Logger.log(data.indexOf("TPBSA"));

回答1:


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'))


来源:https://stackoverflow.com/questions/60818207/function-similar-to-vlookup-why-doesnt-my-indexof-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!