检查ID是否在数组中?

时间:2015-06-08 07:56:45

标签: javascript jquery arrays

我有一个网址传递到我的页面..

var user = new Array();
var list_len = realDataUsers.length;
for(var i=0;i<list_len;i++){
    user['id'] = realDataUsers[i].id;
    if($.inArray(user['id'], tousersArray), 1){
        // get selected state for option
    }

    options = options + "<option value='"+"U|"+user['id'] +"'>"+"User ("+user['name']+")</option>";

}

我有另一个数组,在我的数组循环中,我想检查ID是否存在于URL中传递的ID。但是我不确定如何实现这一目标。大多数情况下,它是如何将URL参数放入数组中,以便进行比较。

有人可以帮忙吗?

<li><a href="https://www.youtube.com/watch?v=YDubYJsZ9iM&amp;list=PL5-da3qGB5IBC-MneTc9oBZz0C6kNJ-f2">Lab: K-means Clustering</a> (6:31)</li>
<li><a href="https://www.youtube.com/watch?v=4u3zvtfqb7w&amp;list=PL5-da3qGB5IBC-MneTc9oBZz0C6kNJ-f2">Lab: Hierarchical Clustering</a> (6:33)</li>
<li><a href="https://www.youtube.com/watch?v=jk9S3RTAl38&amp;list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with John Chambers</a> (10:20)</li>
<li><a href="https://www.youtube.com/watch?v=6l9V1sINzhE&amp;list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with Bradley Efron</a> (12:08)</li>
<li><a href="https://www.youtube.com/watch?v=79tR7BvYE6w&amp;list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interview with Jerome Friedman</a> (10:29)</li>
<li><a href="https://www.youtube.com/watch?v=MEMGOlJxxz0&amp;list=PL5-da3qGB5IC8_kWZXDcmLx7_n4RTBkAS">Interviews with statistics graduate students</a> (7:44)</li>

0 个答案:

没有答案