const arr = [{
"name": "Toyota"
}, {
"name": "Renault"
}, {
"name": "Jeep"
}]
const array_unique = (arr) => Array.from(new Set(arr));
const car = array_unique(
arr.map((item) => item.name),
).sort();
console.log(car); // => ['Toyota', 'Renault', 'Jeep']
const car_map = Object.fromEntries(
car.map((car, index) => [car, index]),
);
console.log(car_map); // => {Toyota: 0, Renault: 1, Jeep: 2,}
Is it possible to replace the numerical indexes like 0, 1, 2 with the car names itself:
{Toyota: Toyota, Renault: Renault, Jeep: Jeep,}