#Use JSON with JS

6 messages · Page 1 of 1 (latest)

crisp walrus

I would like to know how to search more quickly than that

let username = data["guild"]["users"][0]["username"]

where data has been declared and we gave it the JSON parsed file (data.json).

unique templeBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
crisp walrus

Or is there any other way ?

primal lance

data.guild.users[0].username but other than that what are you getting the json from? And do you only want that one user‘s username from it or more information?

crisp walrus
floral wolfBOT

Documentation suggestion for @crisp walrus:
mdn Array.prototype.find()
The find() method of Array instances returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.