将元素添加到多维数组 [英] Add element to multidimensional array
本文介绍了将元素添加到多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我定义了这样的多维javascript数组
if I define a multi-dimentional javascript array like this
//var myStack = new Array(3);
// *** edit ***
var myStack = {};
一次插入一个值的最佳方法是什么?
What is the best way to insert one value at a time?
myStack[1][1][0] = myValue;
我想读取一个数据库并一次写入一个值.示例:
I want to read a database and write one value at a time. Example:
myStack[recordNo][1]['FirstName'] = myValue;
推荐答案
可以通过一行代码插入单个值:
Inserting a single value can be done through one line of code:
myStack[1] = [,[value]];
或者,the之以鼻的方式:
Or, the long-winded way:
myStack[1] = [];
myStack[1][1] = [];
myStack[1][1][0] = value;
这两种方法都将使用多个数组填充数组 myStack
,并根据问题的要求最终设置所需的值.
Either method will populate the array myStack
with multiple arrays, and finally set the desired value, as requested at the question.
对于更新后的问题,可以使用以下内容:
myStack[recordNo] = [,{'FirstName': myValue}];
这篇关于将元素添加到多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文