[英]Random Value from Array Returning a Single Letter
我試圖遍歷電話上的所有聯系人並隨機選擇一個聯系人。 我已經在JavaScript中編寫了以下代碼,並且返回了一個隨機字母。
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!");
}
};
myArray包含一個字符串(displayName),因此,是的,其中的隨機位置是一個字母。 嘗試在比賽中尋找隨機位置,然后返回match [random] .displayName。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.