title: Populating dropdown with GET data from separate JS file
body: <p>I've inherited a project and the original author split their code into separate JS files. One of them contains all of the GET requests, such as Departments, Categories, Titles, etc.</p>
  
  <p>I have some code for an autocomplete dropdown in a separate file, <code>index.js</code>, and <strong>I want to populate the dropdown with the Department results.</strong> I'm not that well-versed in JS and I'm not sure what I have to do to "connect" the files and reference the Departments GET request.</p>
  
  <h3>index.js:</h3>
  
  <pre><code>import "jquery";
  import "jquery-autocomplete/jquery.autocomplete.css";
  import "jquery-autocomplete/jquery.autocomplete.js";
  
  function loadCombobox() {
      let depts = {
          "t1": "1",
          "t2": "2"
      } // added this as a test
  
      let deptsArray = $.map(depts, function(value, key) {
          return {
              value: value,
              data: key
          };
      })
      console.log(deptsArray);
  
      $('#combobox').autocomplete({
          source: deptsArray
      }).on("click", function() {
          console.log("combobox clicked") // works
      });
  }
  
  loadCombobox();
  </code></pre>
  
  <h3>data-request.js</h3>
  
  <pre><code>import axios from "axios";
  
  const baseUrl = siteAbsoluteUrl;
  const deptList = "Department List";
  
  async function makeGetRequest(url) {
    const response = await axios.get(url, getRequestConfig);
    const { results, __next } = response.data.d;
    return { results, __next };
  }
  
  // gives back an array containing all departments, without duplicates
  export async function makeDepartmentsRequest() {
    const { results } = await makeGetRequest(
      `${baseUrl}/getbytitle('${deptBPList}')/fields?$filter=EntityPropertyName eq 'Department'`
    );
    return results[0].Choices.results;
  }
  </code></pre>
  
  <h3>html:</h3>
  
  <pre><code>&lt;input type="text" id="combobox" placeholder="Browse departments"&gt;
  </code></pre>
  
  <h3>console:</h3>
  
  <p><a href="https://i.stack.imgur.com/wTims.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wTims.png" alt="enter image description here"></a></p>