const users = [ { name: 'Ada', score: 91 }, { name: 'Linus', score: 78 }, { name: 'Grace', score: 96 }, ]; // Copy, not mutate — `users` is untouched const ranked = users.toSorted((a, b) => b.score - a.score); const top = ranked.at(0); // no ranked[ranked.length - 1] dance const last = ranked.at(-1); // Group without a reduce() const byBand = Object.groupBy(users, (u) => (u.score >= 90 ? 'high' : 'rest')); // Replace one index, immutably const patched = users.with(1, { ...users[1], score: 80 });