skip to Main Content

I have below request and exported this json body.

export const settingsReq = {
  "states": [
    {
      "initial": false,
      "style": "plain",
      "elements": [
        {
          "type": "question",
          "visible": true,
          "detail": {
            "required": false,
            "extra": {
              "spam_filter_on": true
            },
            "style": "textarea",
            "tenant": {
              "TR": "information"
            }
          },
          "key": "P2E1",
          "triggers": null
        },
        {
          "type": "submit",
          "visible": true,
          "tenant": {
            "TR": "test"
          },
          "key": "P2E2",
          "detail": null,
          "triggers": null
        }
      ],
      "key": "P2"
    },
    {
      "initial": false,
      "style": "thank",
      "elements": [
        {
          "type": "label",
          "visible": true,
          "tenant": {
            "TR": "Thanks everyone"
          },
          "key": "P3E1",
          "detail": null,
          "triggers": null
        }
      ],
      "key": "P3"
    }
  ],
}

In another file I want to access Thanks everyone text.Used below method.

let thanksMessage=settingsReq.states[1].elements[0].tenant.TR

When I use below method code works no problem.But the problem is that the tenant key is underlined in red on Visual Studio Code. As I said,code works correctly even though only the tenant key is underlined(settingsReq.states[1].elements[0].tenant.TR). But why only the tenant key is underlined. How can I turn off tenant key’s error.

2

Answers


  1. The reason why the tenant key is underlined in red in Visual Studio Code is because it is not a valid JavaScript identifier, and Visual Studio Code is flagging it as a syntax error.

    To access the value of the TR property, you can use the square bracket notation instead of the dot notation, like this:

    let thanksMessage = settingsReq.states[1].elements[0].tenant['TR'];
    

    This will allow you to access the TR property without causing a syntax error.

    Alternatively, you can turn off the error highlighting for this specific line by adding a comment at the end of the line, like this:

    let thanksMessage = settingsReq.states[1].elements[0].tenant.TR; // eslint-disable-line
    

    This will tell ESLint to ignore the error on this line. However, this is not recommended, as it will suppress all errors on this line, not just the one related to the tenant key.

    Login or Signup to reply.
  2. you’re missing the detail property
    let thanksMessage=settingsReq.states[1].elements[0].detail.tenant.TR

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