-1

I'm returning an object that has a key defined like this template[body]. Here is an example of the returned object:

object = {
 method: 'patch',
 authentication_token: 'a string',
 template[body]: 'another string',
 ...
}

How can I access the second value? I'm doing something like object.template[body] but I'm getting an error body is undefined

Obonyo
  • 141
  • 1
  • 7

2 Answers2

1

try this solution

You can access the value using object['template[body]'], like so:

let value = object['template[body]'];
connexo
  • 53,704
  • 14
  • 91
  • 128
1

Please try this

console.log(object["template[body]"]);

Thanks

Sanjay
  • 50
  • 8