Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
If you could type an array of objects by their property values utilizing Javascript, then you definitely don’t must look additional than the built-in type
performance.
let individuals = [
{
name : "John",
surname : "Doe",
age : 21
}, {
name : "Jack",
surname : "Bennington",
age : 35
}, {
name : "Jane",
surname : "Doe",
age : 19
}
];
individuals.type((a, b) => a.surname.localeCompare(b.surname));
console.log(individuals);
This will provide you with the next output:
[
{name: 'Jack', surname: 'Bennington', age: 35},
{name: 'John', surname: 'Doe', age: 21},
{name: 'Jane', surname: 'Doe', age: 19}
]
individuals.type((a, b) => {
return a.age - b.age;
});
console.log(individuals);
This will provide you with the next output:
[
{name: 'Jane', surname: 'Doe', age: 19},
{name: 'John', surname: 'Doe', age: 21},
{name: 'Jack', surname: 'Bennington', age: 35}
]