How to access values in a database in the Firebase database?

Asked

Viewed 12 times

-1

I am running the following code:

    var dadosCarro = firebase.database().ref('carro');
    dadosCarro.on('value', (snapshot) => {
      var data = snapshot.val();
      console.log(data)
    });

As an answer on the console, I have:

{-NitWx_oNdW8uFnvmsVh: {…}}
-NitWx_oNdW8uFnvmsVh:
nome: "Onix"
marca: "Chevrolet"
ano: "2021"

How can I access the value of the name attribute, which in this case is "Onix" and assign in a variable?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.