Mike Mike - 3 months ago 14
Javascript Question

reading Javascript object

I have the following object in JavaScript that I capture from the console window:

Object
action: "android.intent.action.SEND"
clipItems: Array[1]
component: "ComponentInfo{com.reunion.family/com.reunion.family.MainActivity}"
extras: Object
android.intent.extra.SUBJECT: "Adam Harris"
android.intent.extra.TEXT: "http://www.adamwadeharris.com/setup-remote-debugging-phonegap/"
share_screenshot_as_stream: "content://com.android.chrome.FileProvider/images/screenshot/1472164245526-1842859201.jpg"
__proto__: —
flags: 318767105
type: "text/plain"
__proto__: —


I can read the outer fields just find and the clipItems object without a issue. However the extras object I'm having a issue reading the "android.intent.extra.TEXT" and " android.intent.extra.SUBJECT" fields.
the object that I wrote out to the console is called: intent

console.log(intent);


so I tried:

intent.android.intent.extra.TEXT
intent.extra.TEXT


but keep gettng a error message :

Error in Success callbackId: IntentPlugin1397752597 : TypeError: Cannot read property 'intent' of undefined


so i must be missing something.

any help would be great.

Answer

You can't use . to access a property name that isn't a valid identifier. Since the property name contains . characters, which are used as delimiters between nested properties, you can't use . to access the property itself. You have to use [] to access it.

intent.extras["android.intent.extra.SUBJECT"]
Comments