Hello I want to push some values into an array but when i alert that array it shows me [object,object],[object,object],[object,object],[object,object]
Does anyone know what the problem is?
Here is the code:
$(document).ready(function() {
$(":button").click(function(event){
var value = $('#box').val();
if (value==""){
return false;
}
else{$.getJSON("http://search.twitter.com/search.json?callback=?&q=value",
function(data){
var array=[];
$.each(data.results, function(i, item){
var user=item.from_user;
var created_at=item.created_at
array.push({date:'created_at',username:'user'});
});alert(array);
});
}
});});
There isn’t a problem.
When you alert an object (which
{date:'created_at',username:'user'}will create) it will be stringified to"[object object]". (You can change that by overriding thetoStringfunction of the object).The array does contain the objects.
(OK, technically there is a problem, but the symptoms you describe are unrelated to it, the values you are putting in to the objects are string literals and not variables, you shouldn’t quote them).