The following is a two dimensional array, I just need to print it, but when I loop inside of it I get [object object]
or undefined
const myarra = function(){
return [
[
{ "dayOfMonth" : 1, "dayOfWeek" : "Fri", "event" : "" },
{ "dayOfMonth" : 2, "dayOfWeek" : "Sat", "event" : "" }
]
];
};
This way you can trace each elements in your array.
Also you can use JSON.stringify(arrayVariable)
method if you just want to print that array using console.log(JSON.stringify(arrayVariable))
this code.
function myfunction(){ var array=[[{"dayOfMonth":1,"dayOfWeek":"Fri","event":""}, {"dayOfMonth":2,"dayOfWeek":"Sat","event":""}]]; for(var i=0;i<array.length;i++){ for(var j=0;j<array[i].length;j++){ console.log(array[i][j]); } } }; myfunction();
You can use JSON.stringify()
const myarra = function(){
return [[{"dayOfMonth":1,"dayOfWeek":"Fri","event":""},
{"dayOfMonth":2,"dayOfWeek":"Sat","event":""}]];
};
JSON.stringify(myarra())
because it first creates this array and then writes
"[[{"dayOfMonth":1,"dayOfWeek":"Fri","event":""},
{"dayOfMonth":2,"dayOfWeek":"Sat","event":""}]];"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.