Ganesh
Ganesh

Reputation: 9

how do i create a dyanmic 2d array in javascript or jquery?

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

];

i need to create this dyanamically using js or jquery

Upvotes: 0

Views: 44

Answers (1)

Rayon
Rayon

Reputation: 36609

In loop, push object in array. To get equivalent of the number in words use toWords.js

Try this:

var len = 10;

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

Upvotes: 1

Related Questions