I am looping through an object and finding whether or not the object has the "key," along with some further stuff.
I feel that there is some other correct way to do this apart from this:
var initialLocalesGen = function(data){
var status;
if(!$.isEmptyObject(data)){
console.log(data);
if(data.hasOwnProperty("username") && data.hasOwnProperty("name")){
var headerHtml = Handlebars.compile($("#header-template").html());
$("#userInfoBar").append(headerHtml({"username" : data["username"], "name" : data["name"]}));
}
if(data.hasOwnProperty("allLocales")){
var formHtml = Handlebars.compile($("#locale-template").html());
$("form legend").after(formHtml(data["allLocales"])).end().find("span.submit").css({display:"block"});
}
if(data.hasOwnProperty("status") && parseInt(data["status"]) === 0){
currentStatus = 0;
var object1 = {"status" : data["status"] , "userLocales": data["userLocales"]}
userLocalesProcess(object1);
}
if(data.hasOwnProperty("status") && parseInt(data["status"]) === 1){
currentStatus = 1;
userChangeProcess({"changeLocales" : data["changeLocales"],"userLocales" : data["userLocales"] });
popupMaker({"message":data["message"],"status":data["status"]});
}
if(data.hasOwnProperty("status") && parseInt(data["status"]) === 2){
currentStatus = 2;
}
}
console.log("currentStatus:", currentStatus);
}
Could anyone help me minimize the condition or show me an even better way of doing it?
data
? \$\endgroup\$