User Interface Expert Question: Download UI Developer PDF
Loop through the "me" object and print each value to the console without assuming you know the keys. Extra bonus: print each color in a separate console.log() without assuming you know the key of "fcolors" (detect the array, and handle printing the values of the array?
Answer:
var me = {"fname": "Global", "lname": "Guideline", "fcolors": ["blue", "green", "whitesmoke"]};
for (var key in me){
if(me.hasOwnProperty(key)){
if(me[key] instanceof Array){
for( var i =0; i < me[key].length; i++ ){
console.log(me[key][i]);
}
} else {
console.log(me[key]);
}
}
}
for (var key in me){
if(me.hasOwnProperty(key)){
if(me[key] instanceof Array){
for( var i =0; i < me[key].length; i++ ){
console.log(me[key][i]);
}
} else {
console.log(me[key]);
}
}
}
Previous Question | Next Question |
Tell me what is the difference between HTML5 interaction in Sencha and Twitter/Bootstrap? | Explain the difference between cookies, sessionStorage, and localStorage? |