Question

I've been trying to get the contact name and last name and also get the cellphone number but when I am using the getAll() method the Console display this:

Found: Daniel Garcia [object Object]

As you can see it displays the Name + LastName + tel. Why does it display tel like [object Object]

Here is my code:

var allContacts = navigator.mozContacts.getAll({
    sortBy: "givenName",
    sortOrder: "ascending"
});  

allContacts.onsuccess = function(event) { 
    if (cursor.result) { 
        if (cursor.result.familyName[0]== undefined) {
            cursor.result.familyName[0]= ""; 
        }  
        console.log("Found: " + cursor.result.givenName[0] + " " + cursor.result.familyName[0] + ' ' + cursor.result.tel[0]); 
        cursor.continue();
    } else {
        console.log("No more contacts");
    }
}
Was it helpful?

Solution 2

Thank you very much it work just like Aras and jamesh proposed

console.log("Found: " + cursor.result.givenName[0] + " " + cursor.result.familyName[0]+' '+JSON.stringify(cursor.result.tel[0]));    

and the console display this:

"Found: Daniel Garcia {"type":["mobile"],"value":"8112441018"}"

OTHER TIPS

tel here is an array of objects - a list of all the possible phone numbers for the contact. Each of this objects has several useful properties. In javascript when you are printing out an object it prints an object string representation (like [object Object]).

Check out docs to understand the structure of the tel object and get it printed the way you want: https://developer.mozilla.org/en-US/docs/Web/API/mozContact.tel

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top