Skip to main content
abhargavc0002
October 4, 2022
Solved

How can we get 1st index elements of each array in different new array

  • October 4, 2022
  • 6 replies
  • 0 views

How can we get 1st index elements of each array in different new array. Like
{2,13,65}
{7,15,45}
{14,3,56}

So output of 1st elements should be {2,7,14}
And for 2nd and 3rd {13,15,3}
{65,45,56}

    Best answer by harshitb6843

    Appian doesn't really understand list of list and therefore it will flatten them into one big array. You might have to cast it in a dictionary so it can iterate on that. 

    a!localVariables(
      local!array:{
        {
          list: {2,13,65}
        },
        {
          list: {7,15,45}
        },
        {
          list: {14,3,56}
        }
        
      },
      a!forEach(
        items: local!array,
        expression: fv!item.list[1]
      )
    )

    You can change the value of 1 to your desired index. 

    6 replies

    harshitb6843
    October 4, 2022

    Appian doesn't really understand list of list and therefore it will flatten them into one big array. You might have to cast it in a dictionary so it can iterate on that. 

    a!localVariables(
      local!array:{
        {
          list: {2,13,65}
        },
        {
          list: {7,15,45}
        },
        {
          list: {14,3,56}
        }
        
      },
      a!forEach(
        items: local!array,
        expression: fv!item.list[1]
      )
    )

    You can change the value of 1 to your desired index. 

    amans0009
    October 4, 2022

    for getting all the three arrays as desired/required

    a!localVariables(
      local!array:{
        {
          list: {2,13,65}
        },
        {
          list: {7,15,45}
        },
        {
          list: {14,3,56}
        },
        {
          list: {1,2,3}
        }
    
      },
      a!forEach(
        items:enumerate(3)+1,  /* three is the no. arrays you have to make/ output arrays */
        expression: a!localVariables(
          local!temp:fv!item,
          a!forEach(
        items: local!array,
        expression: fv!item.list[local!temp]
      )))
    )
    This 3 should not pass the minimun no. of elements(fg-3) in any any list of the array .  

    harshitb6843
    October 4, 2022

    What is the point of copy-pasting the entire code but with increased complexity - one more a!forEach()? That just adds more executing time. 

    amans0009
    October 4, 2022

    Sir, as he said in the question that he wants n(3) arrays accordingly .. so I thought what if the arrays are {1,2,3,4,.....,n} ... So i've edited your code with one extra loop in which he can put the number of required arrays for output. 
      eg - [1,2,3] , [2,4,6], [4,8,9]  should be [1,2,4],[2,4,8],[3,6,9] 
         
    so i've added an extra loop for getting all the arrays as - if you put 2 in the first loop than you can get only [1,2,4],[2,4,6]. and same will work for the n times with a index function also.
    please correct me if I'm wrong

    December 20, 2024

    a!localVariables(
    local!merger: merge({ 2, 13, 65 }, { 7, 15, 45 }, { 14, 3, 56 }),
    local!merger
    )