Expo contacts : query multiple fields

Please provide the following:

  1. SDK Version: 42
  2. Platforms(Android/iOS/web/all): Android/iOS
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hello, I am trying to have a function able to query contacts.

It works well with contact username (text is what I am looking to match)

 const contactsFilteredByName= contacts.filter(function (item) {
      const itemData = item.name
        ? item.name.toUpperCase()
        : ''.toUpperCase();
      console.log("name matched: " + item);
      const textData = text.toUpperCase();  
      return itemData.indexOf(textData) > -1;
    });

But with phone query it returns me only the first number matched. I drives me nuts

  const contactsFilteredByPhone = contacts.filter(function (item) {
     // Check if searched text is not blank
     if (text) {
      let result=[];
       const itemPhoneNumbers = item.phoneNumbers;

       if ((typeof itemPhoneNumbers !== 'undefined' && itemPhoneNumbers !== null && itemPhoneNumbers !== '')  
       ) {
         
        itemPhoneNumbers.forEach((phoneItem) => {
          const textData = text.toUpperCase();
          if (typeof phoneItem.digits !== 'undefined' && phoneItem.digits !== null && phoneItem.digits !== '' ) {
            if (phoneItem.digits.includes(text)) {
              console.log("phone: " + phoneItem.digits + "index: " + phoneItem.digits.indexOf(text) +  " matched: " + item.name);
              result.push(item)
            }
          }
        });
        //remove duplicates when there are several phones matched for a single contact
        uniqueAddresses = Array.from(new Set(result.map(a => a.id)))
        .map(id => {
          return result.find(a => a.id === id)
        })          
        }
     }
   })

The result are in uniqueAddresses…

Are there any chances to make it more simple ?

Many thanks

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.