简体   繁体   中英

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 ?

For example, a normal array lets me do people.manager[2] to get that index (which is 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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