title: JavaScript array.map always returning the last item
body: <p>I have an array of objects, objects look like this:</p>
  <pre><code>interface IDog{
    id: number;
    name: string;
    summary: string;
    wikiLink: string;
    imageLink: string;
    imageAlt: string;
  }
  </code></pre>
  <p>I have this function:</p>
  <pre><code>  private processDog(dogs: IDog[]) {
    return dogs.map((dog) =&gt; {
        let displayCard = this.dogDisplay;
  
        find(displayCard.body, { id: &quot;cardHeader&quot; }).items[0].text = dog.name;
        let adaptiveCard = CardFactory.adaptiveCard(displayCard);
  
        let preview = this.dogPreview;
        preview.content.title = dog.name;
       
        return { ...adaptiveCard, preview };
      });
    }
  </code></pre>
  <p>Now when I call this function, passing an array of Dogs, let's say [DogA, DogB, DogC, DogD]</p>
  <pre><code>    let att = this.processDog(dogs);
  
  </code></pre>
  <p>I am expecting to return an array of the processed dogs as needed, however what's returned is an array of 4 processed dogs of type DogD.. meaning that DogD is shadowing all other dogs in the returned array. What am I doing wrong?</p>
  <p>Full code:</p>
  <pre><code>//First method
        public async onQuery(
          context: TurnContext,
          query: MessagingExtensionQuery
        ): Promise&lt;MessagingExtensionResult&gt; {
       
       const dogs: any = require(&quot;./dogs.json&quot;);
       let att = this.processdog(dogs);
       console.log(att);
       return Promise.resolve({
              type: &quot;result&quot;,
              attachmentLayout: &quot;list&quot;,
              attachments: att, // [{ ...adaptiveCard, preview: defaultPreview }],
            } as MessagingExtensionResult);
      }
  
  //second method
  
   private processdog(dogs: Idog[]) {
    return dogs.map((dog) =&gt; {
        let displayCard = Object.assign({}, this.dogDisplayCard);
  
        find(displayCard.body, { id: &quot;cardHeader&quot; }).items[0].text = dog.name;
        find(displayCard.body, { id: &quot;cardBody&quot; }).items[0].text = dog.summary;
        find(displayCard.body, {
          id: &quot;cardBody&quot;,
        }).items[1].columns[0].items[0].url = dog.imageLink;
        find(displayCard.body, { id: &quot;cardBody&quot; }).items[2].text = dog.imageAlt;
        displayCard.actions[0].url = dog.wikiLink;
        let adaptiveCard = CardFactory.adaptiveCard(displayCard);
  
        let preview = Object.assign({}, this.dogPreviewCard);
  
        preview.content.title = dog.name;
        preview.content.text = dog.imageAlt;
        preview.content.images[0].url = dog.imageLink;
  
        return { ...adaptiveCard, preview };
      });
    }
  </code></pre>
  <p>dogPreview.json:</p>
  <pre><code>{
  &quot;contentType&quot;: &quot;application/vnd.microsoft.card.thumbnail&quot;,
  &quot;content&quot;: {
    &quot;title&quot;: &quot;&quot;,
    &quot;text&quot;: &quot;&quot;,
    &quot;images&quot;: [
      {
        &quot;url&quot;: &quot;&quot;
      }
    ]
  }
  }
  </code></pre>