Hello I have array outside function like below :
var daily = [];
daily["data"]=[];
daily["data"].push('hello');
function demo()
{
console.log(daily); // not working here
}
How to declare this object as global in Javascript ?
It could be because your function is being hoisted. Try this instead for your function.
var demo = function(){
console.log(daily);
}
You might also considering just passing that daily variable into your function like so,
var demo = function(d){
console.log(d);
}
then when you want to call it.
demo(daily);
{}for objects.[]are used for arrays. But then you can't usepushso you need to make up your mind what type of structure you're using.0. See also: andrewdupont.net/2006/05/18/…