arrays - 如何找到列表中元素的所有索引?
问题描述
假设数组中有几个元素是重复的。
数组 = [1,2,4,6,1,6,9,12]
我需要找到 1 的所有索引,这意味着 0 和 4。谁能告诉我该怎么做?
解决方案
下面将一个值数组作为第一个参数,将要查找的值作为第二个参数,并返回找到该值的索引数组:
Function FindIndexesOfElement(valuesArray, elmToFind)
Set indexes = CreateObject("Scripting.Dictionary")
For i = LBound(valuesArray) to UBound(valuesArray)
If elmToFind = valuesArray(i) Then
indexes(i) = True
End If
Next
FindIndexesOfElement = indexes.Keys
End Function
推荐阅读
- r - 基于 R 中的多个变量创建人口普查表
- c++ - 当进程接收到信号时,底层是什么?
- java - 如何在 buttonClick 上的 Accordion 中选择特定的 TitlePane?
- c - 在(好的)旧 printf 的上下文中,长度子说明符“l”有什么影响吗?
- javascript - Sanity Studio 中 LaTex 和表格的序列化程序出现问题 - 未出现在 React 应用程序的前端
- powershell - 不在 DevTestLab 的资源组中时如何拉取 VM AutoShutdown 计划
- android - Android 上的 Ionic/Firebase 应用程序正在重定向到 localhost
- excel - Excel 上 Workbook_SheetChange 的问题
- swift - 关于为什么我的数据没有被传递到新的表格视图的任何想法?
- c# - 在 .NET Core 中进行没有依赖注入的 HTTP 调用