You need a regular "select" list that would fill in the data from the json file by the value field

var json = [ {"value":"2","data":"2019-03-10 00:00:00"}, {"value":"2","data":"2019-03-11 00:00:00"}, {"value":"1","data":"2019-03-12 00:00:00"}, {"value":"1","data":"2019-03-12 18:57:29"}, {"value":"1","data":"2019-03-12 18:57:30"}, {"value":"1","data":"2019-03-12 18:57:40"}, {"value":"1","data":"2019-03-12 18:57:45"}, {"value":"1","data":"2019-03-12 18:58:01"}, {"value":"1","data":"2019-03-12 18:58:10"}, {"value":"1","data":"2019-03-12 18:58:22"} ]; 

How to make select by value

  • What does it mean to transfer to html with the help of DOM js ? What did it mean to select by value ? - Grundy
  • you need a regular select list that would fill in with data from json on the value field - Alexander Shvedov
  • You either express your thought clearly, so that everyone around you can understand what you want. or give the result of the html-code you want to receive. The second is preferable. - teran 7:16 pm

1 answer 1

You have not json , but an array of objects ! ${item.data} for clarity.

 let options, json = [ {"value":"2","data":"2019-03-10 00:00:00"}, {"value":"2","data":"2019-03-11 00:00:00"}, {"value":"1","data":"2019-03-12 00:00:00"}, {"value":"1","data":"2019-03-12 18:57:29"}, {"value":"1","data":"2019-03-12 18:57:30"}, {"value":"1","data":"2019-03-12 18:57:40"}, {"value":"1","data":"2019-03-12 18:57:45"}, {"value":"1","data":"2019-03-12 18:58:01"}, {"value":"1","data":"2019-03-12 18:58:10"}, {"value":"1","data":"2019-03-12 18:58:22"} ], select = document.getElementById('json-select'); json.forEach(function(item) { options += `<option value="${item.value}">${item.data}</option>`; }); select.innerHTML = options; 
 <p>Ваш выбор</p> <select id="json-select"> </select>