Answers.Body: <p>You can achieve this with Craft's <a href="https://docs.craftcms.com/v2/templating/functions.html#shuffle-array" rel="nofollow noreferrer"><code>shuffle()</code> method</a> and Twig's <a href="https://twig.symfony.com/doc/2.x/filters/slice.html" rel="nofollow noreferrer">slice filter</a> (like you mentioned in your answer).</p>
  
  <pre><code>{% set newsletterImages = newsletter.imagesCongratulations.all() %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesCis.all()) %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesSection3.all()) %}
  
  {% set shuffledImages = shuffle(newsletterImages) %}  // Shuffle our "master" array
  
  {% for image in shuffledImages[:6] %}  // Get the first 6 images
    {{ image.title }}&lt;br&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-06T16:11:01.080Z
Answers.Text: Thanks Jalen. Just saw this after I updated my answer. 
  But I prefer your naming approach :-)
Answers.UserDisplayName: Terry Upton
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-06T15:43:07.810Z
Answers.LastActivityDate: 2019-11-06T15:43:07.810Z
Answers.UserDisplayName: Jalen Davenport
Answers.Body: <p>Here is the complete code that achieves what I want. 
  In case it is useful to anyone else.</p>
  
  <pre><code>{% set newsletterImages = newsletter.imagesCongratulations.all() %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesCis.all()) %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesSection3.all()) %}
  
  {% set shuffledImages = shuffle(newsletterImages) %}
  
  {% set transformedImages = [] %}
  
  {% for image in shuffledImages[:6] %}
    {% set transformedImage = craft.imager.transformImage(image, imageTransformParams) %}
    {% set transformedImages = transformedImages|merge([transformedImage]) %}
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-11-06T15:32:45.820Z
Answers.LastActivityDate: 2019-11-06T16:09:30.790Z
Answers.LastEditDate: 2019-11-06T16:09:30.790Z
Answers.UserDisplayName: Terry Upton
Body: <pre><code>{% set newsletterImages = newsletter.imagesCongratulations|merge(newsletter.imagesCis)|merge(newsletter.imagesSection3) %}
  {% set transformedImages = newsletterImages %}
  
  {% for image in newsletterImages %}
    {{ image.title }}&lt;br /&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>newsletterImages is merging images from 3 different global fields.
  I want to then randomise and only output 6 of these images.</p>
  
  <p>However, when I try </p>
  
  <pre><code>{% set transformedImages = newsletterImages.orderBy('RAND()').limit(6) %}
  </code></pre>
  
  <p>I get the error: Impossible to invoke a method ("orderBy") on an array. and Impossible to invoke a method ("limit") on an array.</p>
  
  <p>Can anyone help point me in the right direction to achieve this?</p>
  
Tags: <templating><array>
Title: Impossible to invoke a method on array. How to merge multiple objects and keep as objects
ThreadText: # Impossible to invoke a method on array. How to merge multiple objects and keep as objects
  
  (Asked by: username_0 on 2019-11-06)
  
  ```
  {% set newsletterImages = newsletter.imagesCongratulations|merge(newsletter.imagesCis)|merge(newsletter.imagesSection3) %}
  {% set transformedImages = newsletterImages %}
  
  {% for image in newsletterImages %}
    {{ image.title }}<br />
  
  {% endfor %}
  
  ```
  
  newsletterImages is merging images from 3 different global fields.
  I want to then randomise and only output 6 of these images.
  
  However, when I try
  
  ```
  {% set transformedImages = newsletterImages.orderBy('RAND()').limit(6) %}
  
  ```
  
  I get the error: Impossible to invoke a method ("orderBy") on an array. and Impossible to invoke a method ("limit") on an array.
  
  Can anyone help point me in the right direction to achieve this?
  
  **Tags:** templating, array
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2019-11-06. Score: 2 | Accepted answer
  
  You can achieve this with Craft's [`shuffle()` method](https://docs.craftcms.com/v2/templating/functions.html#shuffle-array) and Twig's [slice filter](https://twig.symfony.com/doc/2.x/filters/slice.html) (like you mentioned in your answer).
  
  ```
  {% set newsletterImages = newsletter.imagesCongratulations.all() %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesCis.all()) %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesSection3.all()) %}
  
  {% set shuffledImages = shuffle(newsletterImages) %}  // Shuffle our "master" array
  
  {% for image in shuffledImages[:6] %}  // Get the first 6 images
    {{ image.title }}<br>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks username_1. Just saw this after I updated my answer.  But I prefer your naming approach :-)  
  
  ---
  
  ### Answer by username_0 on 2019-11-06. Score: 1
  
  Here is the complete code that achieves what I want.
  In case it is useful to anyone else.
  
  ```
  {% set newsletterImages = newsletter.imagesCongratulations.all() %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesCis.all()) %}
  {% set newsletterImages = newsletterImages | merge(newsletter.imagesSection3.all()) %}
  
  {% set shuffledImages = shuffle(newsletterImages) %}
  
  {% set transformedImages = [] %}
  
  {% for image in shuffledImages[:6] %}
    {% set transformedImage = craft.imager.transformImage(image, imageTransformParams) %}
    {% set transformedImages = transformedImages|merge([transformedImage]) %}
  {% endfor %}
  
  ```
  
  
  ---
  
  