0

I'm trying to get password from a json file with below code.

Now the password is shown in console. How can I assign it to a var?

fetch('assets/pwd.json')
          .then(response => {
            return response.json()
          })
          .then(data => {
           console.log((data.password[0]))
          })

2 Answers2

1
fetch('assets/pwd.json')
          .then(response => {
            return response.json()
          })
          .then(data => {
           var password = data.password[0]
           console.log(password)
          })

You can first save the data to a variable, and then you can console log it... It's that simple

0

Why not simply do var pass=data.password[0];

Shardul Birje
  • 341
  • 5
  • 14