I'm looping through an array response and I want to put some values from it into an object data but my method below doesn't work ("data[i] is not defined").
var data = {},
i = 0;
$(response).each(function(){
data[i].title = response.title; // This does not work
data[i].id = response.id;
i++;
}
I want the resulting object data to look like this:
{
0: {
title: "First title",
id: "First id"
},
1: {
title: "Second title",
id: "Second id"
},
}
How can I achieve this?