我有兩個數組,我需要檢查對方,如果他們已經達到了每個數組中的兩個項目實際上彼此相同的點,則追加一些HTML的地方。for循環比較兩個數組尋找匹配的值
下面是碼的一些比特我一直在試圖作爲一個例子:
var daysArray = ["1", "2", "3", "4", "5"];
var courseHwork = ["4", "8", "15", "16", "23", "42"];
所以在陣列上面,只有一個匹配值,是:「4」
這裏的下一個部分:
for (var i = 0; i < courseHwork.length; i++) {
//in my actual code courseHwork contains several objects, each of which
//has a duedate property, so here I want to see if this part of the duedate
//property is equal to any position in the daysArray array.
if (courseHwork[i].duedate.substring(8,10) === daysArray[i]) {
//here I mean to select an element of this class that contains a string
//that is equal to that of the matching positions in both arrays. then
//once found it should take the title property from one of the objects in the
//courseHwork array and append it there.
$('.fc-day-number:contains("'+daysArray[i]+'")').append("<div class='assignment'>"+courseHwork[i].title+"</div><br />");
}
}
如果一切工作按計劃將找到一個div,它包含字符串「4」,並附加從courseHwork數組中的匹配對象屬性「標題」。
注意:我的實際daysArray覆蓋數字爲字符串「1」 - 「31」,並且courseHwork對象數組是動態填充的,因此它可以包含任意數量的對象,但是沒有對象的屬性值超過「 31「在子字符串被找到。
* 問題: 如何可以通過兩個數組表示匹配的值的兩個陣列之間發現的每個時間循環和,一個html元素髮現還包含完全相同的值,則已經東西附加到它? *
合併步驟,合併排序是如何發生的,您可能要查找... – Cameron 2012-03-09 18:31:18
呃 - 是什麼的問題,到底是什麼? – Aprillion 2012-03-09 18:32:35
已更新爲在底部包含更清晰的問題。對困惑感到抱歉。 – captainrad 2012-03-09 18:41:10