Skip to main content
June 16, 2023
Question

Return a list of data based on given indexes

  • June 16, 2023
  • 2 replies
  • 0 views

Hi everyone, 

I have a list of values as given below: 
local!1: {a,b,c,d,e,f,g,h,i,k,l,m,n},

I want to do a loop to index a batch of value each time, for example the first batch is having index 1,2,3 (a,b,c), the next batch with index 4,5,6 (d,e,f),etc (batchsize = 3, start index +3 for each loop)

I tried Enumerate() to determine the exact index of the data I want to get, but this function returns all values from 0 -> batchsize value. Is there anyway that I can get only the index I want, for example 1,2,3 of local!1 for the first loop, then 4,5,6 of local!1 for the second loop and so on? 

Thanks a lot!

    2 replies

    harshitb6843
    June 16, 2023

    a!localVariables(
      local!array: {"a","b","c","d","e","f","g","h","i","k","l","m","n"},
      local!iterations: ceiling(count(local!array)/3),
      a!forEach(
        items: enumerate(local!iterations),
        expression: index(local!array,{1,2,3}+(3*fv!item-1),"")
      )
    )

    June 16, 2023

    First iteration was giving a "" string in list, small change: 

    a!localVariables(
      local!array: {"a","b","c","d","e","f","g","h","i","k","l","m","n"},
      local!iterations: ceiling(count(local!array) / 3),
      a!forEach(
        items: enumerate(local!iterations),
        expression: reject(
          a!isNullOrEmpty(_),
          index(local!array,{ 1, 2, 3 } + fv!item * 3,"")
        )
      )
    )