Answers.Body: <p>You have to break it up into individual values before you can pass it through to JS...</p>
  
  <pre><code>{% includeJsFile "/js/homepage.js" %}
  {% set myJs %}
     playlistData({
        field1: '{{ myObject.field1 }}',
        field2: '{{ myObject.field2 }}',
        field3: '{{ myObject.field3 }}'
     });
  {% endset %}   
  {% includeJs myJs %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-03-31T20:34:16.127Z
Answers.LastActivityDate: 2017-03-31T20:34:16.127Z
Answers.UserDisplayName: Lindsey D
Body: <p>I need to pass an entire Craft object into a JavaScript function. I followed the instructions in this <a href="https://craftcms.stackexchange.com/a/17136/6512">post</a>, however this only covers passing in a string.</p>
  
  <pre><code>{% includeJsFile "/js/homepage.js" %}
  {% set myJs %}
     playlistData('{{myObject}}');
  {% endset %}   
  {% includeJs myJs %}
  </code></pre>
  
  <p>Any ideas?</p>
  
Tags: <includejs>
Title: Pass Craft field object to JavaScript function
ThreadText: # Pass Craft field object to JavaScript function
  
  (Asked by: username_0 on 2017-03-31)
  
  I need to pass an entire Craft object into a JavaScript function. I followed the instructions in this [post](https://craftcms.stackexchange.com/a/17136/6512), however this only covers passing in a string.
  
  ```
  {% includeJsFile "/js/homepage.js" %}
  {% set myJs %}
     playlistData('{{myObject}}');
  {% endset %}   
  {% includeJs myJs %}
  
  ```
  
  Any ideas?
  
  **Tags:** includejs
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-03-31. Score: 4 | Accepted answer
  
  You have to break it up into individual values before you can pass it through to JS...
  
  ```
  {% includeJsFile "/js/homepage.js" %}
  {% set myJs %}
     playlistData({
        field1: '{{ myObject.field1 }}',
        field2: '{{ myObject.field2 }}',
        field3: '{{ myObject.field3 }}'
     });
  {% endset %}   
  {% includeJs myJs %}
  
  ```
  
  
  ---
  
  