Skip to content

Instantly share code, notes, and snippets.

View wojtrawi's full-sized avatar

Wojciech Trawiński wojtrawi

  • Gdansk
View GitHub Profile
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const updatedCars = cars.with(1, 'Mercedes AMG GT R');
console.log(cars);
// ['Ford Mustang', 'BMW M5', 'Porsche 911']
console.log(updatedCars);
// ['Ford Mustang', 'Mercedes AMG GT R', 'Porsche 911']
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const updatedCars = cars.slice();
updatedCars[1] = 'Mercedes AMG GT R';
console.log(cars);
// ['Ford Mustang', 'BMW M5', 'Porsche 911']
console.log(updatedCars);
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
cars[1] = 'Mercedes AMG GT R';
console.log(cars);
// ['Ford Mustang', 'Mercedes AMG GT R', 'Porsche 911']
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const splicedCars = cars.toSpliced(1, 1);
console.log(cars);
// ['Ford Mustang', 'BMW M5', 'Porsche 911']
console.log(splicedCars);
// ["Ford Mustang", "Porsche 911"]
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const splicedCars = cars.slice();
splicedCars.splice(1, 1);
console.log(cars);
// ['Ford Mustang', 'BMW M5', 'Porsche 911']
console.log(splicedCars);
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
cars.splice(1, 1);
console.log(cars);
// ["Ford Mustang", "Porsche 911"]
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const sortedCars = cars.toSorted();
console.log(cars);
// ["Ford Mustang", "BMW M5", "Porsche 911"]
console.log(sortedCars);
// ["BMW M5", "Ford Mustang", "Porsche 911"]
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const sortedCars = cars.slice().sort();
console.log(cars);
// ["Ford Mustang", "BMW M5", "Porsche 911"]
console.log(sortedCars);
// ["BMW M5", "Ford Mustang", "Porsche 911"]
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const sortedCars = cars.sort();
console.log(cars);
// ["BMW M5", "Ford Mustang", "Porsche 911"]
console.log(sortedCars);
// ["BMW M5", "Ford Mustang", "Porsche 911"]
const cars = ['Ford Mustang', 'BMW M5', 'Porsche 911'];
const reversedCars = cars.toReversed();
console.log(cars);
// ["Ford Mustang", "BMW M5", "Porsche 911"]
console.log(reversedCars);
// ["Porsche 911", "BMW M5", "Ford Mustang"]