Error while sorting array of objects Cannot assign to read only property ‘2’ of object ‘[object Array]’

Because the array is frozen in strict mode, you’ll need to copy the array before sorting it:

array = array.slice().sort((a, b) => b.stats.speed - a.stats.speed)

Leave a Comment