0

I've an object and a 1-D array like this:

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'];

I want to find out the index of an element taken from the 'sources' array in the 'nodes' object. For example, the element 'Helping' in the 'sources' array is located at index 2 in 'nodes' object. So I need "2" as my solution when I search for index of the word "Helping". Can somebody help me on this? Thanks.

mplungjan
  • 169,008
  • 28
  • 173
  • 236
PRANAV DASS
  • 41
  • 1
  • 5
  • 1) Please format your code better 2) do you have 8 objects or one object with an array of 8 items? - You will likely find the answer here: http://stackoverflow.com/questions/135448/how-do-i-check-if-an-object-has-a-property-in-javascript – mplungjan May 08 '15 at 05:26
  • 1
    The OP creates 8 objects but assigns them in turn to the same variable named *nodes*, whose value ultimately is a reference to the last object assigned (`{"id": 'Volunteering', "reflexive": true};`). – RobG May 08 '15 at 05:33

0 Answers0