0

While trying to map an array to an object I am getting undefined. How do I pass an object property between these two functions?

This console.log(outputData.movies) returns undefined in the console:

outputData = {};

movies.module = (function($){
  "use strict";
  function app() {
    var intro = {
    fetchData: function fetchData(){
    var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
        var output = JSON.parse(this.responseText);
        outputData.movies       = output.movies.map(movie => movie.title);
        outputData.categories   = output.categories.map(category => category);
        }
      };
      xhttp.open("GET", "http://kexe.dk/dummydata/getlist/?", true);
      xhttp.send();
    },
    parseData: function parseData() {
    console.log(outputData.movies);
    }
}
intro.fetchData();
intro.parseData();
  }
  return {
    app:app
  }    })();

However if i console.log(outputData) it is an object with two properties, only it appears empty until I explore it in the inspector.

dwigt
  • 611
  • 1
  • 8
  • 18

0 Answers0