I am struggling to understand why the inspector is changing what its logging when I expand an array or object:
let newTeamArray = [...teams]; // teams = {randomTeamObject, "Fill"}
let teamList1 = [];
let teamList2 = [];
for(let x = 0; x < newTeamArray.length; x++) {
if(x < (newTeamArray.length/2)) {
console.log("Push to 1")
console.log(newTeamArray[x])
teamList1.push(newTeamArray[x]);
} else {
console.log("Push to 2")
console.log(newTeamArray[x])
teamList2.push(newTeamArray[x])
}
}
console.log(teamList1)
console.log(teamList2)
Can anyone explain why the expanded versions of the last two console.log() commands are different when expanded. Directly after this if I call teamList1[0] its undefined as the inspector shows.
Edit: The array called “teams” is always an even length array. “Fill” is added to the array if it is an odd length. Given that this array only has the one object, fill was added. This happens prior to the code above. My objective is just to split the even array into two arrays the same size called teamList1 & teamList2