javascript - How to check if a property inside a literal is undefined? -



javascript - How to check if a property inside a literal is undefined? -

i have object called at.sports.

and object contains 2 fields: sporttype - string , , team array ...or object.

it's this:

at.sports = { sporttype : "soccer" team : [ { name : "bayern fc", caption: "fcb" } ] }

if check construction in visual studio get:

at.sports = { proto: {}, sporttype: "soccert" team: object object }

and if click on team.. see

0 - name - "arsenal" , caption - "asnl" 1 - name - "bayern fc" , caption - "fcb" want access team property.. check every index (0,1) caption , see if set. if caption undefined.. want replace value of name , capitalize first letter.

ex: index 0 if have name ="arsenal" , caption unset , need caption become "arsenal", , capitalize first letter .. @ end caption = "arsenal" .

i don't know how .. hands on right property , modify.

and i'm curious.. team property.. object or array? think it's object because object object in visual studio when click on at.spors ...

oh..trust me..i researched on google. don't understand how access need within at.sports.

after acces need..i see there method capitalize.. , it's easy alter property value other value. errors in statement.

i tried this:

(var = at.sports.length; i--;) { if (typeof at.sports.team[i] === "undefined") { alert("something undefined"); } }

and alert 2 times. have 2 indexes. so..i'm thinking problem wrong.

if at.sports not array, object definition suggests top, need:

var teamarray = at.sports.team; for(var = 0; < teamarray.length; i++) { if(teamarray[i].name != null && teamarray[i].caption == null) { var n = teamarray[i].name; teamarray[i].caption = n[0].touppercase() + n.substring(1); } }

if array, code sample suggests, this:

for(var = 0; < at.sports.length; i++) { var teamarray = at.sports[i].team; for(var j = 0; j < teamarray.length; j++) { if(teamarray[j].name != null && teamarray[j].caption == null) { var n = teamarray[j].name; teamarray[j].caption = n[0].touppercase() + n.substring(1); } } }

in future, organize question , info better. also, suggested comment question, spend time reading on javascript.

javascript arrays object

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -