javascript - Need a more effective way to loop through a JSON file -
i need better script 1 below. can't add html it. can't add ";" between records. want able add html , list data in: members.name , members.expires , sort data. there more fluid, basic way facilitate requirements?
i have json:
var members = [ {"name": "ahmed, jamshed", "expires": "2017.10.05"}, {"name": "attaya, james", "expires": "2018.01.12"} ];
and script:
<script> var divid = document.getelementbyid("json") for(var i=0;i<members.length;i++) for(var keys in members[i]){ console.log(keys +"-->"+members[i][keys]); divid.innerhtml = divid.innerhtml + " " +members[i][keys]; } </script>
this worked nicely: simpler , more versatile:
<script> var divid = document.getelementbyid("json") string = ""; for(var i=0;i<members.length;i++) { string += members[i].name + " " + members[i].expires +" ● "; } divid.innerhtml = string; </script>
Comments
Post a Comment