我有两个数组,我需要检查对方,如果他们已经达到了每个数组中的两个项目实际上彼此相同的点,则追加一些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