This question already has an answer here:
- How do I test for an empty Javascript object? 29 answers
- Is object empty? 16 answers
function setUserName() {
var usr = AuthService.getUser();
if (typeof usr !== "undefined") {
vs.user = usr;
} else {
vs.user = 'Settings';
}
// if (usr.username === undefined && usr.username === null) {
// vs.user = 'Settings';
// } else {
// vs.user = usr;
// }
console.log(usr);
}
In my code above usr
is currently an empty Object {}
how should this check be written so that it skips down to the else
and set vs.user
to 'Settings'
?
Aucun commentaire:
Enregistrer un commentaire