0

I'm using "react-native-contacts-wrapper" library for selecting contact from the contact list of device. But if there are two contact numbers are saved under one name then it is selecting second one, but I want to select the first one number. Can anybody please help me to do this. Thanks in advance. Here is my code :

...
import ContactsWrapper from "react-native-contacts-wrapper"


const ContactScreen = () => {
...
  (async () => {
    try {
      let pNumber = await ContactsWrapper.getContact();  
      console.log(pNumber.phone)        
    } catch (error) {console.log(error)}
  })() 
}
...
};

Anjali
  • 47
  • 8

1 Answers1

0

Try this,

import ContactsWrapper from "react-native-contacts-wrapper";

const ContactScreen = () => {
  // ...
  (async () => {
    try {
      let contact = await ContactsWrapper.getContact();
      if (contact.phone && contact.phone.length > 0) {
        let firstPhoneNumber = contact.phone[0]; 
        console.log(firstPhoneNumber);
      }
    } catch (error) {
      console.log(error);
    }
  })();
  // ...
};
Anand
  • 4,355
  • 2
  • 35
  • 45
  • Thanks for the reply. But this code is not working. It is giving the first digit of the second number of the contact. means if two numbers in contact name ABC are "123456" and "67890", this code is giving 6 as the output – Anjali Jul 18 '23 at 12:46
  • oh okay @anjali – Anand Jul 18 '23 at 12:54