I need to get that by using the for each function

Certified Senior Developer

Hi all,

{1,2,3,8,9,9,9,9,9,80,90,70}, {56,76,54,32}, {20,23,45,54,32,54}, {1,2,3,4,5,6,7}, {11,12,13,14,15,16,17,18}

Please suggest how do this using foreach function get output like this,


length of array 1 is 12
length of array 2 is 4
length of array 3 is 6
length of array 4 is 7
length of array 5 is 8


Thank You In Advance

  Discussion posts and replies are publicly visible

Parents
    1. Here's the approach I would take (to help you work it out for yourself):Treat each array as a single item in a new array (that is, your new array is a "list of lists")
    2. iterate over that new array using a!forEach()
    3. for each item in the array use the function that tells you how many items are in an array
  • An alternative approach is to use the merge() function to generate a "list of lists" and use the length() function (which ignores null values in its counts):

    a!localVariables(
      local!myArray: fn!merge(
        /*{ 1, 2, 3, 8, 9, 9, 9, 9, 9, 80, 90, 70 },*/
        /*{ 56, 76, 54, 32 },*/
        /*{ 20, 23, 45, 54, 32, 54 },*/
        /*{ 1, 2, 3, 4, 5, 6, 7 },*/
        /*{ 11, 12, 13, 14, 15, 16, 17, 18 }*/
        { 1, 56, 20, 1, 11 },
        { 2, 76, 23, 2, 12 },
        { 3, 54, 45, 4, 14 },
        { 8, 32, 54, 4, 14 },
        { 9, null, 32, 5, 15 },
        { 9, null, 54, 6, 16 },
        { 9, null, null, 7, 17 },
        { 9, null, null, null, 18 },
        { 9, null, null, null, null },
        { 80, null, null, null, null },
        { 90, null, null, null, null },
        { 70, null, null, null, null }
      ),
      a!forEach(
        items: local!myArray,
        expression: fn!length(fv!item)
      )
    )

Reply
  • An alternative approach is to use the merge() function to generate a "list of lists" and use the length() function (which ignores null values in its counts):

    a!localVariables(
      local!myArray: fn!merge(
        /*{ 1, 2, 3, 8, 9, 9, 9, 9, 9, 80, 90, 70 },*/
        /*{ 56, 76, 54, 32 },*/
        /*{ 20, 23, 45, 54, 32, 54 },*/
        /*{ 1, 2, 3, 4, 5, 6, 7 },*/
        /*{ 11, 12, 13, 14, 15, 16, 17, 18 }*/
        { 1, 56, 20, 1, 11 },
        { 2, 76, 23, 2, 12 },
        { 3, 54, 45, 4, 14 },
        { 8, 32, 54, 4, 14 },
        { 9, null, 32, 5, 15 },
        { 9, null, 54, 6, 16 },
        { 9, null, null, 7, 17 },
        { 9, null, null, null, 18 },
        { 9, null, null, null, null },
        { 80, null, null, null, null },
        { 90, null, null, null, null },
        { 70, null, null, null, null }
      ),
      a!forEach(
        items: local!myArray,
        expression: fn!length(fv!item)
      )
    )

Children
No Data