0

I have this object:

var myValues = {
  55bdf7bda89de40349854077: ["hello"]
  55be0c77a89de403498540bc: ["goodbye"]
  55be0e22a89de403498540c1: ["hey there!"]
}

And a variable as contains an id:

var id = '55be0e22a89de403498540c1';

I want to find in the object by this id and get the value in array.

I try to find with:

myValues.id[0]

but ... not works ;/

Anybody can help me?

2 Answers2

1

You need to do myValues[id] or myValues['55be0e22a89de403498540c1']. It's a json object, not a primitive array so you can't access it with indexes like you are trying to do.

Adam
  • 1,724
  • 13
  • 16
1

Your array should like,

var myValues = {
  '55bdf7bda89de40349854077': "hello",
  '55be0c77a89de403498540bc': "goodbye",
  '55be0e22a89de403498540c1': "hey there!"
}

alert(myValues["55be0e22a89de403498540c1"])
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>

May this will help you