Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
<!DOCTYPE html>
<html>
<head>
<title>Array</title>
</head>
<body>
<div id="names-list"></div>
<script>
// Array
let names = ['Larry', 'Curly', 'Moe'];
// Construct HTML unordered list containing the list of names in the array
let html = '<ul>';
// Parse the name out of the names array using a for loop
// The "length" property is used to retrive the size of the array (# of indexes)
for (let i=0;i<names.length;i++) {
// += concatenates and assigns the strings the the "html" variable
html += '<li>' + names[i] + '</li>';
}
html += '</ul>';
// Reference the "names-list" id located in the HTML
let list = document.querySelector('#names-list');
list.innerHTML = html;
</script>
</body>
</html>
Advertisements
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.
AcceptLearn more