skip to Main Content

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

2

Answers


  1. try this solution

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

    let value = object['template[body]'];
    
    Login or Signup to reply.
  2. Please try this

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

    Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search