May 16, 2020 12:27 PM
I have a simple grid view data like that:
and I want to filter my data by company’s uniqueness and get an array which includes list of companies by unique like ['Google', 'Facebook', 'Apple']
read Formula Field Reference but couldn’t find. I can fetch entire data and make filtering on client side but instead of getting entire data, I want to pull only array of companies. By code below so far. Thank you
const RES = await db('users').select({
view: 'Grid view',
filterByFormula: 'some filter should be happen at there',
}).all()
console.log(RES) // should return ['Google', 'Facebook', 'Apple']
May 18, 2020 01:01 AM
Hey you’d want to create an array of the Company, and potentially use ARRAYUNIQUE([item1, item2, item3])
May 18, 2020 05:12 AM
Hi @kaan_g - if RES
is returning an array of users (which I guess it is), then you could do something like:
let unique = [...new Set(RES.map(user => user['Company']))];
console.log(unique);
I haven’t tested this out, but the following works nicely in Airtable scripts, so hopefully you can modify for your code:
let peopleTbl = base.getTable('People');
let query = await peopleTbl.selectRecordsAsync();
let unique = [...new Set(query.records.map(person => person.getCellValue('Company')))];
console.log(unique);
based on this table:
This is creating a new Set
, then “spreading” the values of the Set object to an array.