Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JSON not indexing correctly

I have this JSON:

[
  {
    "type": "GUILD_TEXT",
    "deleted": false,
    "guild": "898666651547996200",
    "guildId": "898666651547996200",
    "parentId": "903388176100495390",
    "permissionOverwrites": [
      "900991433576689675",
      "917426278003523604",
      "898666651547996200",
      "898825198709641246"
    ],
    "messages": [
      "928781911982219307"
    ],
    "threads": [],
    "nsfw": false,
    "id": "903388255528042566",
    "name": "updates",
    "rawPosition": 41,
    "topic": null,
    "lastMessageId": "928781911982219307",
    "rateLimitPerUser": 0,
    "createdTimestamp": 1635454944260
  }
]

(call = the json)

Shouldn’t this be returning "updates": call[0]["name"]

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Via JS, it is returning undefined.

call[0] is returning as {

I’ve tried it on various other languages and it has been working as intended… just not in JS.

>Solution :

It does work:

const call = [{
  "type": "GUILD_TEXT",
  "deleted": false,
  "guild": "898666651547996200",
  "guildId": "898666651547996200",
  "parentId": "903388176100495390",
  "permissionOverwrites": [
    "900991433576689675",
    "917426278003523604",
    "898666651547996200",
    "898825198709641246"
  ],
  "messages": [
    "928781911982219307"
  ],
  "threads": [],
  "nsfw": false,
  "id": "903388255528042566",
  "name": "updates",
  "rawPosition": 41,
  "topic": null,
  "lastMessageId": "928781911982219307",
  "rateLimitPerUser": 0,
  "createdTimestamp": 1635454944260
}]

console.log(call[0]["name"]) // updates
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading