const vehicle = [
{
a: [
{
vehicle_name: "Toyota",
color: "black"
},
{
vehicle_name: "Toyota",
color: "red"
},
{
vehicle_name: "Ford",
color: "yellow"
},
{
vehicle_name: "Toyota",
color: "white"
}
]
},
{
b: [
{
vehicle_name: "Honda",
color: "black"
},
{
vehicle_name: "Honda",
color: "red"
},
{
vehicle_name: "Ford",
color: "yellow"
},
{
vehicle_name: "Toyota",
color: "white"
}
]
}
]
Given the array of obj above, My goal is to get the total number of vehicle in each key. Note: if the vehicle_name is repeated it should only count as 1. Expected Output:
const result = [
{
a: {
count: 2
}
},
{
b: {
count: 3
}
}
]
Explanation: The count of key a => is 2 because although it have 4 vehicles but Toyota is repeated so it only count as 1. Same goes in key b => the count is 3 because it has three different name(Honda, Ford, Toyota)