JSON data - create and fill <select> using "createElement" method CODE
Creates
<select>
element using
document.createElement
method and fills with JSON array
optionArray = [
    "daily",
    "weekly",
    "biweekly",
    "monthly"
];

// Creates <select> element
let selector = document.createElement('select');

for(let option in optionArray) {
    let value = optionArray[option];
  
    // Creates <option> element for <select>
    let newOption = document.createElement("option"); 
    
    newOption.value = value;
    newOption.innerHTML = value;
  
    selector.options.add(newOption);
}
// Adds the <select> element into the document object
document.body.appendChild(selector);
by Valeri Tandilashvili
4 years ago
JSON
JavaScript
1
Pro tip: use ```triple backticks around text``` to write in code fences