如果我有一个多维数组,我怎样才能只访问第一个维度的第一个值?
If I have a multidimentional array, how can I acsess only the first value of the first dimention?
如果我有一个多维数组,我怎样才能只访问第一个维度的第一个值。我来解释一下:
sampleArray=new Array[];
sampleArray[0]=["Nouns","Adjectives","Verbs"];
sampleArray[1]=["Colors","Time","Sound];
sampleArray[0][0]=["Person","Place","Thing"]
我只想获取 Nouns
这个词,但是当我尝试获取 sampleArray[0][0]
的值时,结果只会是 Person, Place, Thing
!
在您的示例代码中 "Nouns" 实际上位于
sampleArray[0][0]
但是您要将其替换为
sampleArray[0][0]=["Person","Place","Thing"]
也许将您的信息保存在一个对象中会更容易。然后以这种方式引用它们。不确定您的最终目标是什么,所以这可能不适合您。
var partsOfSpeach = {};
var noun = {};
noun.name = "Noun";
noun.def = ["Person","Place","Thing"];
partsOfSpeach.Noun = noun;
然后您可以在
访问信息
trace(partsOfSpeach.Noun.name); // "Noun"
trace(partsOfSpeach.Noun.def); // "Person","Place","Thing"
如果我有一个多维数组,我怎样才能只访问第一个维度的第一个值。我来解释一下:
sampleArray=new Array[];
sampleArray[0]=["Nouns","Adjectives","Verbs"];
sampleArray[1]=["Colors","Time","Sound];
sampleArray[0][0]=["Person","Place","Thing"]
我只想获取 Nouns
这个词,但是当我尝试获取 sampleArray[0][0]
的值时,结果只会是 Person, Place, Thing
!
在您的示例代码中 "Nouns" 实际上位于
sampleArray[0][0]
但是您要将其替换为
sampleArray[0][0]=["Person","Place","Thing"]
也许将您的信息保存在一个对象中会更容易。然后以这种方式引用它们。不确定您的最终目标是什么,所以这可能不适合您。
var partsOfSpeach = {};
var noun = {};
noun.name = "Noun";
noun.def = ["Person","Place","Thing"];
partsOfSpeach.Noun = noun;
然后您可以在
访问信息trace(partsOfSpeach.Noun.name); // "Noun"
trace(partsOfSpeach.Noun.def); // "Person","Place","Thing"