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 +" &#9679; ";  }  divid.innerhtml = string; </script> 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -