how to reach the JSON
below and populate the img
tag's src
?
I was trying to reach it by using the regular method using the dot syntax but it won't work:
data.images[0].image
<!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>Slider</title>
</head>
<body>
<div class="sliderContainer">
<img src="data.images[0].image" placeholder="example" />
</div>
<script type="text/javascript" src="./index.js">
const data = {
images: [
{ ID: 0, name: 'name1', image: 'images/example1.jpg', link:'#' },
{ ID: 1, name: 'name2', image: 'images/example2.jpg', link:'#' },
],
};
</script>
</body>
</html>
select image element by id
and then