After fetching data from an API and passing it to index.js using getServerSideProps, I noticed that the prop array is initially in order by rank [1, 2, 3, etc].
Here's an example of the data:
[
{rank: 1, price: 123},
{rank: 2, price: 1958},
{rank: 3, price: 56}
]
However, when I manipulate this data into a different variable like so:
const topPrice = data
.sort((a, b) => a.price < b.price ? 1 : -1)
.slice(0, 3);
The console log now shows that the original `data` is also sorted by price, even though I only intended for `topPrice` to be sorted. Why is this happening?