getting weird result when trying to copy an array using slice() on VS Code

I’m doing the “Chunky Monkey” practice on freeCodeCamp and I’m trying to debug the program on VS Code. But I’m getting a different result than the one I get when I try to run it on the fCC console. fCC returns the expected result for the case, the original array,, but I get a different output on VS Code. Here’s the code I made:

function chunkArrayInGroups(arr, size) {
    let groupArr = arr.slice(0);   // VS Code returns [4, 5, 6, 7]
    //console.log(groupArr)
    const groupTarget = Math.ceil(arr.length / size);
    console.log(groupTarget)
    let group = 1;
    console.log(group)
    let finalArr = [];
    for (let i = 0; i < size; i++) {  // iterates though the array 'size' times 
      if (group == groupTarget) {     // if for when we are on the last array to fill
        for (let j = 0; j < size; j++)  // for to iterate size amount of times to see if there is no undefined
        {
          if (groupArr[j] == undefined) { //if there is a undifined value, we'll make a smaller array for the last group 
            finalArr.push(groupArr.splice(0, j))
            console.log(finalArr)
          }
        }
      }
      finalArr.push(groupArr.splice(0, size))  // if we are not on the last group, we just splice the original value and push it 
      console.log(finalArr)
    } 
    return finalArr; // once loops end, we return the finalArray
  }
  
  chunkArrayInGroups([0, 1, 2, 3, 4, 5, 6, 7, 8], 4); 

Hope someone is able to help. Did I mess up something on VS Code? I only copied the exact code that I had.