如何在此 JavaScript 数组上调用 .get() 方法?
How to call .get() method on this JavaScript array?
首先,请看这张截图:
我想就此调用 .get("p" + number)
,但是我尝试这样做时得到 undefined
或这个:
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)
正如评论中所指出的,对象没有 get
方法。如果你想访问特定 属性 的值,你可以只用括号或点符号引用 属性(参见 MDN 上的 Property Accessors):
//dot notation:
Global.refPatients["_object"].p151833309;
//bracket notation - needed if you want to get 15183309 from a variable:
Global.refPatients["_object"]["p"+151833309];
首先,请看这张截图:
我想就此调用 .get("p" + number)
,但是我尝试这样做时得到 undefined
或这个:
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)
正如评论中所指出的,对象没有 get
方法。如果你想访问特定 属性 的值,你可以只用括号或点符号引用 属性(参见 MDN 上的 Property Accessors):
//dot notation:
Global.refPatients["_object"].p151833309;
//bracket notation - needed if you want to get 15183309 from a variable:
Global.refPatients["_object"]["p"+151833309];