Javascript 我在尝试创建数字字符串值的2D数组时出错
当我运行console.log时,我得到了所有正确的返回值,但是chrome说将location初始化为var location=[]时出错;我和我的同学都不明白为什么Javascript 我在尝试创建数字字符串值的2D数组时出错,javascript,arrays,string,2d,tostring,Javascript,Arrays,String,2d,Tostring,当我运行console.log时,我得到了所有正确的返回值,但是chrome说将location初始化为var location=[]时出错;我和我的同学都不明白为什么 var location = []; /*This set of loops should create a 2D array called location and assign a string value to match it's position in the 2D array so that
var location = [];
/*This set of loops should create a 2D array called location and assign
a string value to match it's position in the 2D array so that
location[0][0] == "00" and location[2][1] == "21".
*/
for(var i = 0; i < row; i++) {
location[i] = [];
for(var j = 0; j < col; j++) {
location[i][j] = i.toString() + j.toString();
console.log("i" + i +"\tj"+ j + " "+ location[i][j]);
}
}
var位置=[];
/*这组循环应该创建一个名为location和assign的二维数组
匹配其在二维数组中位置的字符串值,以便
位置[0][0]=“00”和位置[2][1]=“21”。
*/
对于(变量i=0;i|
“位置”是窗口的只读属性。把你的代码放在一个函数中,它就会工作。编辑不是真正的“只读”,但其类型是固定的;它是位置对象(URL、查询字符串等)。