I am trying to loop through all the contacts on a phone and pick one contact randomly. I have written the code below (in JavaScript) and it is returning a single random letter.
function callme(){
var options = new ContactFindOptions( );
options.filter = "";
options.multiple = true;
var filter = ["displayName"];
navigator.contacts.find(filter, successFunc, errFunc, options); // ...?
//alert("present");
function successFunc( matches ){
for( var i=0; i<matches.length; i++){
var myArray = matches[i].displayName;
var random_contact = myArray[Math.round(Math.random() * (myArray.length - 1))];
}
alert(random_contact); //alerting random letter
}
function errFunc(){
alert("oh no!");
}
};