I'm assigning values to an object and I need to assign a generated value that comes from an ajax response?
this is my assign code line:
var object1 = object1.map(function(el) {
var o = Object.assign({}, el);
$.ajax({
url: "/api/getcolor?age=7, // this will return a sequence of object according to the item in object1 e.i {"color":"red"} {"color":"blue"} {"color":"yellow"}
type: 'GET',
dataType: 'json',
success: function(data) {
console.log("data: "+JSON.stringify(Object.values(data)))
var myColors = JSON.stringify(Object.values(data))
}
});
o.color= myColors ; // reassigning to object colors --> which means whatever was resturned from the ajax response should replaceeach value in object > o.color
}
my issue is, how do I access variable myColors outside of the ajax response and assign it to o.color? is there a better way of achieving this?
THANKS!