我有一个包含多个值的数组,我想比较某些值是否彼此相等,如果有超过 1 个等于它,则将值放入新数组中
例:
for(var i=0; i<res.data.diaries.length;i++){
var values = res.data.diaries[i].diary.symptoms;
if( typeof values.whichSymptoms !== 'undefined' ) {
// foo could get resolved and it's defined
for(var j= 0; j<values.whichSymptoms.length;j++){
//console.log(values.whichSymptoms[j].text);
var whichSymptoms = values.whichSymptoms[j];
console.log(whichSymptoms);
//// ToDo Check values if equal and put that in an array.
}
}
}
好的,现在知道了... 变量计数 = {}; 变量元素; myArray.forEach(function(element) { 计数[元素] = (计数[元素] || 0) + 1; }); var donat症状 =[]; var donat症状计数 =[]; 对于 ( 计数中的元素) { donatSymptoms.push(element); donatSymptomsCount.push(counts[element]) console.log(element + ' = ' + counts[element]); } console.log(donat症状,donat症状计数);