js array ob obects unqi code example
Example 1: javascript unique array of objects by property
const array =
[
{ "name": "Joe", "age": 17 },
{ "name": "Bob", "age": 17 },
{ "name": "Carl", "age": 35 }
]
function uniqueByKey(array, key) {
return [...new Map(array.map((x) => [x[key], x])).values()];
}
console.log(uniqueByKey(array, 'age'));
Example 2: devolver nombre propiedades de objeto javascript
var coche =new Auto("Seat", "Ibiza", 90, 2010, 5000);
console.log(Object.keys(coche))
//Array(6) [ "marca", "modelo", "potencia", "antiguedad", "precio", "edadAprox" ]