Create HTML table from JavaScript object

前端 未结 8 1140
后悔当初
后悔当初 2020-12-05 12:02

I am a beginner of JavaScript and want to display an array of objects in HTML.

The format of the data is like this:

[
  {\"key\":\"apple\",\"value\":         


        
8条回答
  •  生来不讨喜
    2020-12-05 12:31

    Iterate through the list and retrieve the data for each item this way (assuming your data is in a var called data):

    for (var i = 0; i < data.length; i++) {
      var id = i + 1;
      var name = data[i].key;
      var relevance = data[i].value;
    }
    

    Then, do something with the variables in each loop, print them out however you want.

提交回复
热议问题