Why is splice() not working in the web editor?

I may be missing something very simple here. I am trying to use splice to add 0 onto the front of this array. However, the result of both console logs are [0,1,2,3,4,5]. It’s like it is retroactively adding the zero to the first console log. I try this exact code on other javascript editors and it works as intended. Any help would be great.

function setup() {
  let A = [1,2,3,4,5]
  console.log(A)
  A.splice(0,0,0)
  console.log(A)
}
function setup() {
  createCanvas(400, 400);
  let A = [2,3,4,5,6]
  console.log(A.length)
  console.log(A)
  console.log(A.length)
  if(A.length == 5){
    A.push(1) 
    console.log(A)
  }
}

More confusion on my part. Screenshot of console:

1 Like

BtW, we can use method unshift() in order to append at the front (head) of an array: A.unshift(0)