-4

I've following object and I need to access

let tempID= options._baseid; 

options->_metadata->98bb74e9-b168-4b83-8019-306af8fed977->name

However I'm unable to access this and value is always undefined.

This is my object:

enter image description here

This is the the javascript data variable. Same as the screenshot.

{
  "_parent": null,
  "_metadata": {
    "sTID": null,
    "sID": null,
    "iType": null,
    "lIDList": null,
    "lEList": null,
    "SfS": null,
    "sSrcID": null,
    "sSrcType": null,
    "98bb74e9-b168-4b83-8019-306af8fed977": {
      "id": "98bb74e9-b168-4b83-8019-306af8fed977",
      "type": 2,
      "name": "newTemplate0508"
    }
  },
  "_baseid": "98bb74e9-b168-4b83-8019-306af8fed977",
  "_sourcetype": "2"
}
  • 3
    Possible duplicate of [How to access object properties containing special characters?](https://stackoverflow.com/questions/12953704/how-to-access-object-properties-containing-special-characters) and [Object property name as number](https://stackoverflow.com/questions/16908476) – adiga May 10 '19 at 05:27
  • 1
    Welcome! `options["_metadata"]["98bb74e9-b168-4b83-8019-306af8fed977"]["name"]` – Kaushik May 10 '19 at 05:27
  • I tried with bracket notation too but still value is undefined. – TechProgrammer May 10 '19 at 05:42

2 Answers2

-1

try to access as following

yourObj._metadata[yourObj._baseid].name;
Chin Shuu
  • 51
  • 1
  • 2
  • 9
-1

Use the bracket notation instead of dot.

let tempID = options['_baseid']; 
options['_metadata']['98bb74e9-b168-4b83-8019-306af8fed977']['name']
Sharan Mohandas
  • 861
  • 1
  • 9
  • 25