title: How to reference an object in an array of objects using Bicep
body: <p>I am trying to output the referenceId of each subnet in a module that creates a virtual network with 4 subnets. I can get the first one, <code>[0]</code>, but when I try output the others, <code>[1], [2], [3]</code> the deployment fails and throws the error:</p>
  <p><code>The language expression property array index &quot;1&quot; is out of bounds</code></p>
  <p>Below is the code to create the virtualNetwork and the subnets:</p>
  <pre><code>resource virtualNetwork 'Microsoft.Network/virtualNetworks@2018-11-01' = {
    name: vNetName
    location: location
    tags: tags
    properties: {
      addressSpace: {
        addressPrefixes: [
          addressPrefix
        ]
      }
      subnets: subnets
    }
  }
  </code></pre>
  <p><code>subnets</code> is a variable of type array:</p>
  <pre><code>var subnets = [
    {
      name: mgmtSubnetName
      properties: {
        addressPrefix: mgmtSubnetAddressPrefix
      }
    }
    {
      name: intSubnetName
      properties: {
        addressPrefix: intSubnetAddressPrefix
      }
    }
    {
      name: extSubnetName
      properties: {
        addressPrefix: extSubnetAddressPrefix
      }
    }
    {
      name: vdmsSubnetName
      properties: {
        addressPrefix: vdmsSubnetAddressPrefix
      }
    }
  ]
  </code></pre>
  <p>When I use the output line below, it returns and array that has 4 objects...one for each subnet created:</p>
  <p><code>output subnets array = virtualNetwork.properties.subnets</code></p>
  <p>Each object has the format below:</p>
  <pre><code>{
      &quot;name&quot;:&quot;&lt;value&gt;&quot;,
      &quot;id&quot;:&quot;&lt;value&gt;&quot;,
      &quot;etag&quot;:&quot;&lt;value&gt;&quot;,
      &quot;properties&quot;:{
          &quot;provisioningState&quot;:&quot;Succeeded&quot;,
          &quot;addressPrefix&quot;:&quot;&lt;value&gt;&quot;,
          &quot;ipConfigurations&quot;:[
              {
                  &quot;id&quot;:&quot;&lt;value&gt;&quot;
              }
          ],
          &quot;delegations&quot;:[]
      },
      &quot;type&quot;:&quot;Microsoft.Network/virtualNetworks/subnets&quot;
  }
  </code></pre>
  <p>When I use the output line below, it returns the first object in the subnets array:</p>
  <p><code>output subnet1 object = virtualNetwork.properties.subnets[0]</code></p>
  <p>When I use the output line below, it returns the <code>resourceId</code> of the first subnet:</p>
  <p><code>output subnet1 string = virtualNetwork.properties.subnets[0].id</code></p>
  <p>I am unable to retrieve the other objects in the array using indexes <code>1, 2,</code> or <code>3</code>.</p>
  <p>I have also tried the <code>resourceId</code> function (example below) but the behavior is exactly the same for indexes <code>1, 2,</code> or <code>3</code>:</p>
  <p><code>output subnet1Id string = resourceId('Microsoft.Network/VirtualNetworks/subnets', name, subnets[0].name)</code></p>