English 中文(简体)
1. 界定多面阵列,并用 j
原标题:Define a multi dimensional array with javascript
  • 时间:2011-09-09 13:50:54
  •  标签:
  • javascript

我有:

var Test = new Array();
Test = ("Rose","India",564,375,new Array(5,6,7),".net");

但我要界定这一阵列的关键:

Test = ("Rose" => "Pleb",
      "India" => "Test",
       564,
       375,
      new Array(5,6,7),
      ".net");

But that doesn t work. How is this done?

问题回答

在javascript、阵列和物体中有两个数据结构(实际上,阵列是一种特殊用途,但现在并不对此感到关切)。 一个阵列是收集星群;钥匙可能是非毗连的(即不需要0,1,2,3,可能达到0,51,52,99,102)。 你们可以把财产划给一阵列,但这使得对这些财产进行挖掘更加困难。

物体是可与阵列非常相似地检索的专有钥匙。

瞬间阵列的最简单方式是阵列(使用平方字节),而制造物体的最简单方式是物体字面字面(使用曲解包解):

var myArray = []; // creates a new empty array

var myOtherArray = [ "foo", "bar", "baz"]; // creates an array literal:
// myOtherArray[0] === "foo"
// myOtherArray[1] === "bar"
// myOtherArray[2] === "baz"
//

//
// This would be reasonably called a multidimensional array:
//
var myNestedArray = [ [ "foo", "bar", "baz"], [ "one", "two", "three"] ];
// myNestedArray[0] => [ "foo", "bar", "baz"];
// myNestedArray[1] => [ "one", "two", "three"];
// myNestedArray[0][0] === "foo";
// myNestedArray[1][0] === "one";

var myObject = {}; // creates an empty object literal

var myOtherObject = {
    one: "foo",
    two: "bar",
    three: "baz"
};
// myOtherObject.one === "foo"
// myOtherObject["one"] === "foo" (you can access using brackets as well)
// myOtherObject.two === "bar"
// myOtherObject.three === "baz"
//

//
// You can nest the two like this:
var myNestedObject = {
    anArray: [ "foo", "bar", "baz" ],
    anObject: {
        one: "foo",
        two: "bar",
        three: "baz"
    }
}

也许你可以尝试这种做法:

    // Declare an array to hold all of the data grid values
    var dataGridArray = [];

    // Turn dataGridArray into a 2D array
    for (arrayCounter = 0; arrayCounter < document.getElementById("cphMain_dtgTimesheet").rows.length - 2; arrayCounter++) {

        // Create a new array within the original array
        dataGridArray[arrayCounter] = [];

    } // for arrayCounter

我希望这有一定帮助。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签