Javascript Creating Object -


i creating object :

var obj = {     "id": 0,     "matchdate": $scope.match.matchdate,     "status": 0,     "hometeam": { "id": 0, "teamid": 0, "matchid": 0, "name": '', "players": [{ "id": 0, "playerid": 0, "matchid": 0, "teamid": 0, "name": '' }] },     "visitorteam": { "id": 0, "teamid": 0, "matchid": 0, "name": '', "players": [{ "id": 0, "playerid": 0, "matchid": 0, "teamid": 0, "name": '' }] } } 

how can create default, empty properties object this:

var obj = {     "id": ,     "matchdate":,     "status": ,     "hometeam": { "id": , "teamid": , "matchid": , "name": , "players": [{ "id":, "playerid": , "matchid": , "teamid": , "name":  }] },     "visitorteam": { "id": , "teamid": , "matchid": , "name": '', "players": [{ "id": , "playerid": , "matchid": 0, "teamid": , "name": '' }] } } 

why need this? because want object created start, , add values later.

you can explicitly give value undefined, can't omit value entirely.

var obj = {     "id": undefined,     // etc }; 

that said, nothing stopping omitting properties don't have , setting them later.


Comments