regarding the code block below, i have a class that i use to create multiple objects, with each object containg some basic information about a particular car. i have created at the end, an array of these objects. how can i sort out this array of the objects based on a value like say, their weight, in ascending order from smallest to heaviest.
class raceCar {
constructor(name, weight, lenght, width, height, horsePower, torque, colour){
this._name = name;
this._weight = weight;
this._lenght = lenght;
this._width = width;
this._height = height;
this._horsePower = horsePower;
this._torque = torque;
this._colour = colour;
}
get name(){
return this._name;
}
get weight(){
return this._weight;
}
get lenght(){
return this._lenght;
}
get width(){
return this._width;
}
get height(){
return this._height;
}
get horsePower(){
return this._horsePower;
}
get torque(){
return this._torque
}
get colour(){
return this._colour
}
}
const a45s = new raceCar ('a45s', 1550, 4445, 1850, 1412, 421, 500, 'black');
const m135i = new raceCar ('m135i', 1525, 4319, 1799, 1434, 306, 450, 'blue')
const golfR = new raceCar ('golfR', 1408, 4263, 1799, 1465, 310, 380, 'green')
const m240i = new raceCar ('240i', 1475, 4454, 1774, 1408, 340, 500, 'blue')
const cupra = new raceCar ('cupra', 1490, 4398, 1799, 1442, 300, 400, 'white')
var carArray = [a45s, m135i, golfR, m240i, cupra]