如何在jquery或js中创建动态二维数组 [英] How to create dynamic two dimensional array in jquery or js
本文介绍了如何在jquery或js中创建动态二维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在jquery或javascript中创建全局二维数组
I need to create global two dimensional array in jquery or javascript
我的功能就是这样
<script>
var globalArray[0] = new Array();
function createArray(){
alert(globalArray[0]);
}
</script>
<div><input type='button' value='save' onclick='createArray();'> </div>
单击该按钮时,我得到此错误"globalArray[0] is undefined"
On click of that button I am getting this error "globalArray[0] is undefined"
如何创建全局动态多维数组.
How can I create global dynamic multi dimensional array.
推荐答案
if (!globalArray[index])
globalArray[index] = []; // init the array.
globalArray[index].push(name);
您有一个带点的错字:
$.("#uname").val();
更改为:
$("#uname").val();
您打算如何处理此代码?
What are you trying to do with this code?
更新 :(问题已完全编辑.)
Update: (The question was totally edited.)
您的代码:
var globalArray[0] = new Array();
globalArray[0]
是无效的变量名,您需要首先声明该数组:
globalArray[0]
is invalid variable name, you need first to declare the array:
var globalArray = []; // Array literal.
globalArray[0] = [] // The element at position 0 is new an array.
这篇关于如何在jquery或js中创建动态二维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文