Your statement is invalid.
This code shows both console.log are printing the same array every single round.
function bubbleSort(arr) {
let array = [...arr];
let sorted = false;
let round = 0;
while (!sorted) {
sorted = true;
console.log({ array }, `Round no. ${round}`); // this shows the already sorted array
console.log(array, `Round no. ${round}`); // this shows the array after one round of sorting
for (let i = 0; i < array.length - 1 - round; i++) {
if (array[i] > array[i + 1]) {
[array[i], array[i + 1]] = [array[i + 1], array[i]];
sorted = false;
}
}
round++;
}
return array;
}
bubbleSort([10,7,15,1]);
This is what I get when I execute this snippet
{
"array": [
10,
7,
15,
1
]
} Round no. 0
[
10,
7,
15,
1
] Round no. 0
{
"array": [
7,
10,
1,
15
]
} Round no. 1
[
7,
10,
1,
15
] Round no. 1
{
"array": [
7,
1,
10,
15
]
} Round no. 2
[
7,
1,
10,
15
] Round no. 2
{
"array": [
1,
7,
10,
15
]
} Round no. 3
[
1,
7,
10,
15
] Round no. 3
PS: If you mean you open it in Chrome Console (or something similar) and it looks like this
then it depends on implementation of that console.
The value of both, array and { array } is the position in memory, where the array-values are persisted. These values are changing, so if it did not persist the value of array back in time you logged it, but just the value of the memory segment, then when you expand it, it shows you the current values, not the historical ones.