for example, I want to add "msg" keys only when msg is not null:
myFunction: function(msg){
var jsonObj={
"name" :"abc",
"time" : 12345,
};
if(msg!==undefined){
jsonObj["msg"]=msg;
}
return jsonObj;
}
but I don't want the if statements, is there any syntax to write something like that:
myFunction: function(msg){
var jsonObj={
"name" :"abc",
"time" : 12345,
msg!==null?["msg":msg]:nothing
};
return jsonObj;
}
?