Obasi Obeny Oj Obasi Obeny Oj - 1 day ago 4
TypeScript Question

How to check in an object has key in angular2

I have the following object let usersVal = snapshot.val();

The console.log

3TngNGbwMVhc5kJ2b3wAULEIP6g1
Object
photoUrl
"https://scontent.xx.fbcdn.net/v/t1.0-1/ss"
provider
"facebook.com"
signup
1480596548396
useremail
"someemail@yahoo.com"
username
"James nan"
__proto__


c834vePyJ3SFVk2iO4rU0ke1cSa2
photoUrl
"https://firebasestorage.googleapis.com/v0/b/ff"
provider
"google.com"
signup
1480600290735
useremail
"3333@gmail.com"
username
"Ericel123eessdd"
__proto__
Object


I want to check if object has uid key. If it does I set some boolan value to true

this.users = af.database.object('/some-users', { preserveSnapshot: true });
this.users.subscribe(snapshot => {
let usersVal = snapshot.val();
if(key in usersVal){
this.userId = true;
}

});


How can I achieve this in an angular2 component?

Answer

Should be as simple as

let usersVal = snapshot.val();
if (usersVal["uid"]) {
    ...
}
Comments