List all items from a for loop with javascript -
i'm looking way list each firstname below loop. loops through each firstname stoping @ last jack , displaying that. want display of them like: john, jane, joe
var person = [{firstname:"john"}, {firstname:"jane"}, {firstname:"jack"}]; (var = 0; < person.length; i++) { document.getelementbyid("demo").innerhtml = person[i].firstname; }
can advise on how this?
the problem overwriting innerhtml
value, instead need append values innerhtml
property using '+':
var person = [{firstname:"john"}, {firstname:"jane"}, {firstname:"jack"}]; var demo = document.getelementbyid("demo"); (var = 0, len = person.length; < len; i++) { demo.innerhtml += person[i].firstname + ' '; }
check out codepen. have add modifications make code more performant.
Comments
Post a Comment