在对象javascript中查找数组元素的索引

时间:2015-05-08 05:23:30

标签: javascript arrays javascript-objects

我有一个对象和一个像这样的一维数组:

nodes = {"id": 'Habitat for Humanity', "reflexive": true};
nodes = {"id": 'Caring', "reflexive": true};
nodes = {"id": 'Helping', "reflexive": true};
nodes = {"id": 'People', "reflexive": true};
nodes = {"id": 'Security', "reflexive": true};
nodes = {"id": 'Shelter', "reflexive": true};
nodes = {"id": 'Community', "reflexive": true};
nodes = {"id": 'Volunteering', "reflexive": true};

var sources = ['Helping', 'Community', 'Caring', 'Safety', 'Security'];

我想找出从'nodes'对象中'sources'数组中取出的元素的索引。例如,'sources'数组中的'Helping'元素位于'nodes'对象的索引2处。所以当我搜索“帮助”这个词的索引时,我需要“2”作为我的解决方案。有人可以帮我吗?感谢。

0 个答案:

没有答案
相关问题