How can I prevent A from changing its value when I only want to modify Q in the first loop of this html/javascript code?
- Why does A change even though I am only changing Q?
- What steps can I take to avoid A from changing?
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var A=[[3,4],[5,7]];
var Q=[];
for (var k=0;k<2;k++){
Q= A;
for (var i=0;i<2;i++) {
Q[k][i]=1;
}
}
document.getElementById("demo").innerHTML = A;
</script>
</body>
</html>