by using for...of loop.
Use the below reference image link:
https://assets.ccbp.in/frontend/content/dynamic-webapps/ce-3-1-3-for-of-loop-op.png.
Achieve the design using the
for...of loop to iterate over an array in the JS prefilled code.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
</head>
<body>
<h1>Cars</h1>
<ul id="container"></ul>
<script>
const container = document.querySelector('#container');
const cars = ['Benz', 'Ferrari', 'Audi', 'BMW'];
cars.map(e => {
const car = document.createElement('li');
car.textContent = e;
container.appendChild(car)
})
</script>
</body>
</html>
Comments