Javascript 如何使用JS(类似于css第n个选择器)确定索引是否位于列表中的组内

Javascript 如何使用JS(类似于css第n个选择器)确定索引是否位于列表中的组内,javascript,angularjs,Javascript,Angularjs,我需要确定索引是否是未确定列表中11个组中的第二个项。在css中,我可以使用第n个选择器执行此操作: :nth-child(11n + 2) 列表是一个数组,所以组只是我使用的一个计数器 listLength = X groupLength = 11 indexCheck = 2 selectedIndex = Y 我不想使用循环来执行此操作,因为我确信有更好的方法来确定组位置和所选索引位置 它不是数组的数组。它是一个单一的项目数组,对于我想确定的每11个项目,我的索引是这11个项目中的第2

我需要确定索引是否是未确定列表中11个组中的第二个项。在css中,我可以使用第n个选择器执行此操作:

:nth-child(11n + 2)
列表是一个数组,所以组只是我使用的一个计数器

listLength = X
groupLength = 11
indexCheck = 2
selectedIndex = Y
我不想使用循环来执行此操作,因为我确信有更好的方法来确定组位置和所选索引位置

它不是数组的数组。它是一个单一的项目数组,对于我想确定的每11个项目,我的索引是这11个项目中的第2个。我需要这样做,以便我可以对该计数/组中该项目必须唯一的项目应用一些逻辑

例如:

2是前11个计数/组中的第二项

13是第二个11计数/组中的第二项

24是第三个11计数/组中的第二项

下面是一个示例,显示的是单个数组格式

[
1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18
]

我有数组中项目的索引,我只需要在检查计数后计算其位置。

请检查此项,并说明是否适合您

    data = [
      1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ,21,22,23,24
      ]
      groupLength = 11
      indexCheck = 17

   const len = this.data.length;// get the length of the array
    const getInd = this.data.indexOf(this.indexCheck) + 1; // get the index of the given value 
    if(getInd == 0){
      // value is not present just return
      console.log('this index is not present in the array')
      return;
    }
    //From the index divide by grouplength and round by math ceil method. In item variable holds how much group can be splitted inside data array if we given 13 then it will take 2 groups
    const item = Math.ceil(getInd / this.groupLength);
    const groupIndex = this.groupLength * item;
    // itemIndex holds the in which index the value is present in array by splitting in to groups
    let itemIndex = null
    if(groupIndex == this.groupLength){
      itemIndex = getInd
    }else{
      itemIndex = getInd - (groupIndex - this.groupLength)
    }

    console.log(`${this.indexCheck} is the ${itemIndex} item in the ${this.groupLength} count/group `)

请检查

您的术语有点混乱。你有数组吗?要遍历和搜索的对象/数组的结构是什么?是否需要访问或查找任何特定数组元素?还是只需要对给定的值进行某种数学验证?真的很不清楚你到底想要什么,所以请编辑这个问题,并提供一个实际的例子,说明你有什么输入数据,以及你期望基于此得到什么具体结果。我用一个例子更新了这个问题,说明我试图从列表中得到什么。