如何在Angularjs中声明二维数组可变,其中数组大小因用户输入而变化 [英] How Can I Declare 2D Array Varible In Angularjs Where Array Size Varies Based On User Input

查看:395
本文介绍了如何在Angularjs中声明二维数组可变,其中数组大小因用户输入而变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

how can i declare 2D array varible in angularjs where array size varies based on user input

推荐答案

请参阅我对该问题的评论。这取决于你想如何使用2D阵列。 JavaScript不需要多维数组的概念,因为你总是可以构造它们。



例如,你可以这样做:

Please see my comment to the question. It depends on how you want to use the "2D array". JavaScript does not require the notion of "multidimensional" arrays, because you can always construct them.

For example, you can do this:
var myArray = [["a", "b"], ["c", "d", "e"], ["f"]];
myArray[3] = [1, 2]; // new element appended to outer array
var object = myArray[1][2];
myArray[1][3] = "e2"; // appended new element to inner array after "e"



阵列可能令人惊讶。请执行此操作,看看会发生什么:


Arrays can be surprising. Please do this and see what happens:

myArray[10] = 1;





数组 - JavaScript |网站设计MDN [ ^ ],

关联数组 - 维基百科,免费的百科全书 [ ^ ]。



-SA


这篇关于如何在Angularjs中声明二维数组可变,其中数组大小因用户输入而变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆