Q:

how to dynamically filter with react-native realm

I am switching to realm for react native and would like to make use of their built in queries/filtering. I have checkbox filters with 3 possible options, the selected are passed as a array:
var filters = ['complete', 'inProgress', 'notStarted']

How can i filter without using multiple if/else statements?
  let subdivisions = realm.objects('Subdivision');
       let result = subdivisions.filtered('statusSurvey == $0',['complete','notStarted']);

Or is it necessary to use plain javascript or lodash?

A:

Here's another way to do it without building the query in a string, and having to escape the filter values:
filters = ['a', 'b', 'c']
const realmFilter = [Array(filters.length).fill().map((x, i)=> `statusSurvey == $${i}`).join(" OR ")].concat(filters)

realm.objects('Subdivision').filtered(...realmFilter)

A:

Are you asking how to dynamically build a realm query string that would return results based off the current filters? 
If I'm understanding correctly, you could build your query string like: 
var query = 'statusSurvey == ';
for (var i = 0; i < filters.length; i++) {
  query += `'${filters[i]}'`; 
  if (i + 1 < filters.length) {
    query += ` OR statusSurvey == `
  }
}
var result = subdivisions.filtered(query); 

