简体   繁体   English

在另一个数组中查找数组的索引

[英]Find index of array inside *another* array

var people = {};

people.manager = [12,13,14]

people.cashier = [6,7,8]

The above is an example of code that I am doing. 上面是我正在执行的代码示例。 It is not about "managers" or anything but I made this up to make it more easy to answer. 这不是关于“经理”或任何东西,而是我做了这个,以使其更易于回答。

My question is that: how do I find a certain 'key' (apparently it is not called 'index') of people ? 我的问题是:如何找到有一定的“钥匙”(显然它不叫“索引”) people

For example, a normal array lets me do people.manager[2] to get that index (which is 14 ). 例如,普通数组让我执行people.manager[2]来获取该索引(即14 )。

EDIT: I changed index to key because it might make more sense. 编辑:我将索引更改为键,因为它可能更有意义。

With objects, you can use bracket notation to try and pull a key (not index) out. 对于对象,可以使用方括号表示法尝试拉出键(而非索引)。

So, you could do: 因此,您可以执行以下操作:

var key = "manager";
people[key][2]; //14

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM