Skip to content

A nested loop variation #13280

Closed Answered by GABRIELNGBTUC
housten asked this question in Q&A
Feb 9, 2024 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

Nested looping is not possible but using map() you can create the desired outcome:

var test = [
  {
    name: 'name'
    products: [
      1
      2
    ]
  }
]

var productByName = [for item in test: map(item.products, product => {
  name: item.name
  product: product
})]

output testFlatten array = flatten(productByName)

testFlatten resolves to the following array:

[{"name":"name","product":1},{"name":"name","product":2}]

Which you can then loop over with the items() function.

Also I would not rely on ChatGPT for anything bicep related. If Github copilot which uses real repositories as a data source can't get it right most of the time, a LLM that confidently spits false information is …

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by housten
Comment options

You must be logged in to vote
1 reply
@GABRIELNGBTUC
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants