与vlookup类似的功能:为什么indexOf不能正常工作? [英] Function similar to vlookup: Why doesn't my indexOf work?

查看:62
本文介绍了与vlookup类似的功能:为什么indexOf不能正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想匹配需要与Excel中的<lookup>相同的单词.我打算为Example创建一个表格.我有一个特定的大数据文件,我将创建一个框用于填充您需要的数据,然后输入以显示数据描述.现在我被卡住了,我不知道该怎么写我在youtube上学到的脚本,但是没有一个解决方案,我需要在<Indexof>函数附近.

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"));

推荐答案

data是2D(二维)数组. indexOf仅适用于一维数组. flat 在indexOf之前的数组:

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

这篇关于与vlookup类似的功能:为什么indexOf不能正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆