I am a beginner programmer trying to transfer four properties from my JSONP array into a new array for every item.
$.ajax({
url: etsyURL,
dataType: 'jsonp',
success: function(data) {
if (data.ok) {
var a = (data.results);
//create a parent array to store all objects
var bigarray = [];
$.each(a, function(i, item) {
//assign values from response to variables
var atitle = item.title;
var aurl = item.url;
var aimg = item.Images[0].url_75x75;
var aprice = item.price;
//create an object
var object = {
title: atitle,
url: aurl,
img: aimg,
price: aprice
};
//add the object into big array for every each item, unsure
})
}
}
});
My end goal is to get bigarray to get all all items in objects like below:
bigarray = [{title:"xbox", url:"www.web.com", pic:"www.pic.com/w.png",price:"100"}, {title:"ps4", url:"www.web.com", pic:"www.pic.com/p.png",price:"110"}]
Question
1. How do I add objects based on the number of items in the array?
2. Any other methods are welcomed, I will accept the answer even if $.even is replaced with a for loop.
bigarray[] = object;data.resultsis an array you don't need$.each()->Array.prototype.map(), otherwise use$.map()(+.get())