I'm using $.getJSON to return a promise object. But I want to store the data before it goes through cleanData() in a variable called 'unclean'. I also want the data that goes through cleanData() to be stored in a variable called 'clean'. Right now this is not working-- when I do this (below) and log both unclean and clean they are the same (the data after cleanData())
var unclean, clean;
getData('data/allmetros.json')
.then(function(data1) {
unclean = data1;
return cleanData(data1);
}).done(function(data2) {
clean = data2;
console.log(unclean, clean);
});
function getData(url) {
return $.getJSON(url);
}
function cleanData(data){
//do something to clean the data
return data;
}