简体   繁体   中英

How do I access the following nested property of a large object?

console.log(mustaccessthis)

returns:

Element {
  sessionId: 'cca3f23e-2dac-46ef-8b00-7b644475b861',
  elementId: '77d27a45-4b88-45b5-8843-0f1833d64387',
  'element-6066-11e4-a52e-4f735466cecf': '77d27a45-4b88-45b5-8843-0f1833d64387',
  selector: ".//*",
  index: 0,
  emit: [Function: bound ],
  addCommand: [Function] }

I am trying to access the elementId , here is what I have tried:

  • mustaccessthis.elementId
  • mustaccessthis.Element.elementId
  • mustaccessthis.Element.elementId
  • mustaccessthis[0].elementId

None of these are returning the value.

How would I grab that elementId value for comparisons etc?

Error returned is nearly always

"Cannot read property 'elementId' of undefined"

Try doing

 mustaccessthis['elementId']

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors#Bracket_notation

elementid is invalid syntax, it is trying to mix array and objects but also no brackets or braces. So that is your error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM