Javascript集合 - 获取集合的关键

时间:2014-12-22 16:38:14

标签: javascript jquery html arrays object

我对获取数组或对象的键非常困惑。

如何获得密钥:

var arr = [0, 2, 5];
findKey(array, 5);

如何获得密钥;

var obj = {'Abc': {name: 'Sample'}};
findKey(obj, 'Sample'); // Find the index, not abc. Get 0 here.

如何获得密钥:

var obj = {'Room1': ['User1', 'User2', 'User3']};
findKey(obj, 'User1'); // Find the index, not Room1. Get 0 here.

0 个答案:

没有答案