Creating an array should be second nature by now. I hope! Remember, there are two ways to create an array.
var myArray = new Array();
var myArray = [];
What method do we use to add something to array?
myArray.push(myelement);
How do we access or change elements in the array?
var element = myArray[0]; // access an index in the array
myArray[0] = element; // change an index in the array
Can you use the array on your canvas? I would create a simple array instance and making sure you can make it appear on the canvas.
<html>
<head>
<title>Canvas</title>
<style>
#myCanvas{
border:black;
border-style: solid;
border-width: 2px;
}
</style>
</head>
<body>
<canvas id="myCanvas" height="600" width="800"></canvas>
<script>
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
var x = 50;
var y = 50;
ctx.fillStyle = "#0000FF";
drawSquare();
function update()
{
drawSquare();
}
function drawSquare()
{
ctx.fillRect(x, y, 20, 20);
}
</script>
</body>
</html>
Alter the code above to make sure your array items appear on the canvas.