I want to filter the data based on flag1 = "Standard" or flag2 = "Standard" and get the unique customer names met with the filter data. The expected output here for the above API response is
Hey @saravanakumar84! Looks like you're trying to filter an array of objects by a set of specific values in each object, and then extract one particular object field. Actually a pretty common use case in Retool!
The way I would do this is something like:
// Filter for objects containing "standard" for flag1 or flag2
const filteredArray = originalArray.filter(function(item) {
return (item.flag1 === "Standard" || item.flag2 === "Standard")
});
// Filter for unique objects using Lodash
const uniqueObjects = _.uniqBy(filteredArray, 'customer_name');
// Extract just the customer name from those objects
const customerNames = uniqueObjects.map(item => item.customer_name);
// Returns an array
You can also combine the last two steps for simpler syntax: