How to get the key from a Firebase data snapshot?

前端 未结 5 1317
南旧
南旧 2021-02-01 02:52

I\'m able to query my users array with an e-mail address and return the user\'s account info:

users.orderByChild(\'email\').equalTo(authData.user.em         


        
5条回答
  •  南笙
    南笙 (楼主)
    2021-02-01 03:33

    You could do something like this:

    var key = Object.keys(snapshot.val())[0];
    

    Ref: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

    The Object.keys() method returns an array of a given object's own enumerable properties, in the same order as that provided by a for...in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

提交回复
热议问题