JavaScript: Get the value of a dinamicly generated object -



JavaScript: Get the value of a dinamicly generated object -

i know can access value of user defined variable composing name like

window["myvariable"+1234]

what don't know how access value of inner properties. want next code, works:

//suppose there object user-generated property names mycars.ford.focus.mileage , need function reports value of property when content not empty string. create function function squealproperty(maker,model,udprop){ if(window["mycars."+maker+"."+model+"."+udprop+".length"] > 0){ alert("user defined property inspector ("+udprop+")="+window["mycars."+maker+"."+model+"."+udprop]); }; };

in moments this, find answers prayers in "the book"[1] no luck time. inquire here. [1] "the book" mean "javascript: definitive guide", 5th edition. david flanagan

you can not access propertys single string when access them []. have break them down. code break if seek check @ 1 time, have check 1 "inner" property @ every check.

function squealproperty(maker,model,udprop){ if(window["mycars"] && window["mycars"][maker] && window["mycars"][maker][model] && window["mycars"][maker][model][udprop] && window["mycars"][maker][model][udprop].length > 0){ alert("user defined property inspector ("+udprop+")="+window["mycars"][maker][model][udprop]); }; };

javascript object window

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 -