如何在javascript或jquery中创建dyanmic 2d数组?

时间:2016-02-23 05:59:55

标签: javascript jquery arrays

var Mydata= [
    {
        value: 1,
        label: "One"
    },
    {
        value: 2,
        label: "Two"
    },
    {
        value: 3,
        label: "Three"
    },
    {
        value: 4,
        label: "Four"
    },
    {
        value: 5,
        label: "Five"
    }

];

我需要使用js或jquery

来创建这个动态

1 个答案:

答案 0 :(得分:1)

  

loop中,在object中推送array。要使用toWords.js

获得与单词相同的数字

试试这个:



var len = 10;

var Mydata = [];
for (var i = 1; i < len; i++) {
  Mydata.push({
    value: i,
    label: toWords(i.toString())
  });
}
console.log(Mydata);
&#13;
<script src="http://gh-canon.github.io/stack-snippet-console/console.min.js"></script>
<script src="http://javascript.about.com/library/toword.js"></script>
&#13;
&#13;
&#13;