简体   繁体   English

如果我有一个多维数组,如何只访问第一维的第一个值?

[英]If I have a multidimentional array, how can I acsess only the first value of the first dimention?

If I have a multidimentional array, how can I acsess only the first value of the first dimention. 如果我有一个多维数组,如何只访问第一个维的第一个值。 I will Explain: 我会解释:

sampleArray=new Array[];

sampleArray[0]=["Nouns","Adjectives","Verbs"];
sampleArray[1]=["Colors","Time","Sound];
sampleArray[0][0]=["Person","Place","Thing"]

I would just like to get the word Nouns but when I try to get the value of sampleArray[0][0] it will just result Person, Place, Thing ! 我只想得到Nouns但是当我尝试获取sampleArray[0][0]的值时,它只会导致Person, Place, Thing

In your sample code "Nouns" is actually located at 在示例代码中,“名词”实际上位于

sampleArray[0][0]

However you are replacing that with 但是,您将其替换为

sampleArray[0][0]=["Person","Place","Thing"]

Perhaps it would be easier to keep your information in an object. 将信息保存在一个对象中也许会更容易。 Then reference them that way. 然后以这种方式引用它们。 Not sure what your end goal is though so that may not work for you. 不确定您的最终目标是什么,因此可能对您不起作用。

var partsOfSpeach = {};
var noun = {};
noun.name = "Noun";
noun.def = ["Person","Place","Thing"];
partsOfSpeach.Noun = noun;

Then you can access the info at 然后您可以在以下位置访问信息

trace(partsOfSpeach.Noun.name); // "Noun"
trace(partsOfSpeach.Noun.def); // "Person","Place","Thing"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Powershell中的多维数组中获取值 - How can I get the value from a multidimentional array in Powershell 如何替换多维数组中的重复值? - How can i replace duplicates value from multidimentional array? 如何在第一个值上对数组排序? - How can I sort an array on the first value? 我如何只知道一些值就可以找到多维数组的数组索引? 例如'id'=>'Id2' - How can I find out array index of multidimentional array, knowing only some value ? For instance 'id'=>'Id2' 如何过滤多维数组中的重复项? - How can I filter a multidimentional array for duplicates? 如何从数组数组中提取在第一个字段中具有相同值的所有数组? - How can I extract from an array of arrays all the arrays that have the same value in their first field? 如何检查没有固定维度的二维数组的第一行是否都具有相同的值? - How can I check if the first row of a 2D array with no fixed dimension all have the same value? 如何在多维数组上获得第一把钥匙 - How to get first keys on multidimentional array 如何在 python 中仅添加数组的第一个元素? - How can I add only the first elements of an array in python? 如何仅在每个JSON对象中获取第一个值 - How can I get first value only in each JSON object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM