I am currently working on extracting the slug value from an array within the object.extra.services. The goal is to find the element in this array that matches the ID I provide...
// Service ID provided
const serviceID = '5cdd7c55f5abb90a689a44be';
// Array of services Ids
getProductsServices(products) {
const productsServices = [
...new Set(products.map(product => product.extra.services))
];
const productsList = [].concat.apply([], productsServices);
return productsList;
},
// ServiceId Matching
serviceMatch(serviceID) {
return this.getProductsServices.includes(serviceID);
}
Now, I need to retrieve the slug value from the array that corresponds to the provided service ID.
products [{
"_id" : ObjectId("5e0257dcbe760674b10d4122"),
"desc" : "Website Design",
"extra" : {
"image" : "/2018/06/design-of-logos-for-companies.jpg",
"services" : [
"5cdd7c55f5abb90a689a44be",
"5cdd7c55f5abb90a689a3fcc",
"5cdd7c55f5abb90a689a3f42"
]
},
"name" : "Logo Design",
"slug" : "online-logo-design"
},
{
"_id" : ObjectId("5e0257dcbe760674b10d4122"),
"desc" : "Logo Design",
"extra" : {
"image" : "/2018/06/design-of-logos-for-companies.jpg",
"services" : [
"5cdd7c55f5abb90a689a44be",
"5cdd7c55f5abb90a689a3fcc",
"5cdd7c55f5abb90a689a3f42"
]
},
"name" : "Logo Design",
"slug" : "online-logo-design"
},
{
"_id" : ObjectId("5e0257dcbe760674b10d4122"),
"desc" : "Interior Design",
"extra" : {
"image" : "/2018/06/design-of-logos-for-companies.jpg",
"services" : [
"5cdd7c55f5abb90a689a44be",
"5cdd7c55f5abb90a689a3fcc",
"5cdd7c55f5abb90a689a3f42"
]
},
"name" : "Logo Design",
"slug" : "online-logo-design"
}]