我找不到这个问题的答案,我试图在排序数组中找到下一个值,这是我的代码:
for (i = 0; i < arrayKeys.length; i++) {
var records = myContacts[arrayKeys[i]];
// Sort each names
records = records.sort(sortNames);
// Now, Lets run over the sorted array
for (var r_key in records) {
// If we have the same name more then once we will add the phone number for both of them
var sphone = (records[r_key].name==records[r_key+1].name) ? true : false; //That's wrong to put here +1
var rname=records[r_key].name;
if (sphone) {
var sphone = " - " + records[r_key].pNumber; // Adding the phone number
} else sphone = "";
console.log(rname+sphone);
}
}
例如,结果可以是:
- 本尼
- 约翰
- 米歇尔 - 0378766667
- 米歇尔 - 0365556664
- 弗拉德
- ...
那么,我如何将当前值与下一个值进行比较,并将电话号码添加到两个名称中?