以下是二维数组,我只需要打印它,但当我在其中循环时,我得到[object object]
或undefined
const myarra = function(){
return [
[
{ "dayOfMonth" : 1, "dayOfWeek" : "Fri", "event" : "" },
{ "dayOfMonth" : 2, "dayOfWeek" : "Sat", "event" : "" }
]
];
};
答案 0 :(得分:1)
这样您就可以跟踪数组中的每个元素。
如果您只想使用JSON.stringify(arrayVariable)
此代码打印该数组,也可以使用console.log(JSON.stringify(arrayVariable))
方法。
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();
&#13;
答案 1 :(得分:0)
您可以使用JSON.stringify()
const myarra = function(){
return [[{"dayOfMonth":1,"dayOfWeek":"Fri","event":""},
{"dayOfMonth":2,"dayOfWeek":"Sat","event":""}]];
};
JSON.stringify(myarra())
答案 2 :(得分:-1)
因为它首先创建此数组然后写入
"[[{"dayOfMonth":1,"dayOfWeek":"Fri","event":""},
{"dayOfMonth":2,"dayOfWeek":"Sat","event":""}]];"