iterate over a map key

Certified Lead Developer

Hi Champs,

I have a map value having multiple key and value pair. Now I want to check for a value which exists in one or more key. So I guess the only way to do that is to iterate over the keys in the map. 

How can I achieve the same. As of my knowledge, for each works for no of map not for no of key/value pair in a map.

Regards,

Ghanashyam

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    If you define an array of your key names you can iterate over them with a nested a!forEach(). Example below, you can do what you want with the test and return value on the inner loop.

    a!localVariables(
      local!map: {
        a!map(
          label: "Map 1",
          key1: "A",
          key2: "C",
          key3: "C"
        ),
        a!map(
          label: "Map 2",
          key1: "C",
          key2: "A",
          key3: "B"
        ),
        a!map(
          label: "Map 3",
          key1: "C",
          key2: "B",
          key3: "C"
        )
      },
      local!definedKeys: { "key1", "key2", "key3" },
      a!forEach(
        items: local!map,
        expression: a!localVariables(
          local!innerMap: fv!item,
          a!forEach(
            items: local!definedKeys,
            expression: if(
              local!innerMap[fv!item] ="C",
              fv!item,
              {}
            )
          )
        )
      )
    )

Reply
  • 0
    Certified Lead Developer

    If you define an array of your key names you can iterate over them with a nested a!forEach(). Example below, you can do what you want with the test and return value on the inner loop.

    a!localVariables(
      local!map: {
        a!map(
          label: "Map 1",
          key1: "A",
          key2: "C",
          key3: "C"
        ),
        a!map(
          label: "Map 2",
          key1: "C",
          key2: "A",
          key3: "B"
        ),
        a!map(
          label: "Map 3",
          key1: "C",
          key2: "B",
          key3: "C"
        )
      },
      local!definedKeys: { "key1", "key2", "key3" },
      a!forEach(
        items: local!map,
        expression: a!localVariables(
          local!innerMap: fv!item,
          a!forEach(
            items: local!definedKeys,
            expression: if(
              local!innerMap[fv!item] ="C",
              fv!item,
              {}
            )
          )
        )
      )
    )

Children
No Data