0

First, look at this screenshot:

Console

I would like to call .get("p" + number) on this, but however I try to do this I get undefined or this:

Global.refPatients["_object"].get(p151833309)

Uncaught TypeError: Global.refPatients._object.get is not a function
    at <anonymous>:2:31
    at Object.InjectedScript._evaluateOn (<anonymous>:895:140)
    at Object.InjectedScript._evaluateAndWrap (<anonymous>:828:34)
    at Object.InjectedScript.evaluate (<anonymous>:694:21)
David Thomas
  • 249,100
  • 51
  • 377
  • 410
  • 2
    `Global.refPatients["_object"].p151833309`? There is no built-in `get` method on objects, and `p151833309` isn’t a variable. – Ry- Jul 18 '15 at 19:11
  • Nope, `still it is not a function` – Michał Gątkowski Jul 18 '15 at 19:12
  • What is not a function? There is no function being called there, so it’s impossible for you to get the same error. – Ry- Jul 18 '15 at 19:12
  • 2
    First, what are you trying to do? What do you think the (non-existent) `get()` method should do? Having asked that, it looks like you're trying to retrieve value held in that object key, so perhaps you want: `Global.refPatients.p151833309`? – David Thomas Jul 18 '15 at 19:13
  • Yup, sorry, I've added. get() at the end, your line works, but how do i place a var in place of pp151833309 ? I would like to pass that object to a variable.. – Michał Gątkowski Jul 18 '15 at 19:15
  • 2
    `Global.refPatients["_object"]["p" + number]`? – dfsq Jul 18 '15 at 19:15
  • 1
    Global.refPatients["_object"]["p" + id] – Ananth Jul 18 '15 at 19:15

1 Answers1

1

As pointed out in the comments, objects don't have a get method. If you want to access the value of a particular property, you can just reference the property with either the bracket or the dot notation (see Property Accessors on MDN):

//dot notation:
 Global.refPatients["_object"].p151833309;

//bracket notation - needed if you want to get 15183309 from a variable:
Global.refPatients["_object"]["p"+151833309];
doldt
  • 4,466
  • 3
  • 21
  • 36
  • Actually i found out that i can do something like this: `Global.refPatients.get("p151954902")` which i think is less complicated than your solution, anyway, thank you! ;) – Michał Gątkowski Jul 19 '15 at 10:32
  • 2
    @MichałGątkowski that must be a custom method defined on `refPatients` or its prototype then, regular Javascript objects don't have a `get` method. – doldt Jul 19 '15 at 11:25