I have an array of objects, and I'd like to randomize the order of the elements.
So I have the following:
const animals = data?.fetchAllAnimals;
let randomizeAnimals = animals.sort(()=> Math.random() -0.5 )
But I keep getting this error in firefox:
TypeError: 0 is read-only
and a different error in chrome:
TypeError: Cannot assign to read only property '0' of object '[object Array]'
What am I doing wrong here?
let randomizedAnimals = [...animals]; randomizedAnimals.sort(() => Math.random() - 0.5);and everything is working okay now