0

I have a url passed to my page as such..

domain.com/users=1237,3728,5686

I have another array whereby in my loop of this array I want to check to see if the ID exists from those passed in the URL. However I am unsure how to achieve this. Mostly, it's how to get the URL params into an array so I can make a comparison.

Can anyone help?

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>";

}
Peter
  • 913
  • 1
  • 12
  • 24
Suba
  • 199
  • 1
  • 2
  • 11
  • 1
    How does the `tousersArray` look like? – TaoPR Jun 08 '15 at 07:58
  • 4
    What's with the `, 1` inside the `if` condition? Please read the documentation before you use an unfamiliar function: https://api.jquery.com/jQuery.inArray/ – Felix Kling Jun 08 '15 at 08:01
  • You're trap in a similar situation to : `if (1==1,0) { alert(1)}` because the last argument is 0 so it is falsy. as opposed to `if (1==0,5) { alert(1)}` which is truthy due to 5. Also I would be glad to know the spec term for this (x,y) thing – Royi Namir Jun 08 '15 at 08:04
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Jun 08 '15 at 08:04
  • 1
    Does your URL actually look like the example you gave? Usually there is a question mark like: "domain.com?users=1237" This post might help: [How can I get query string values in JavaScript?](http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript) – Yogi Jun 08 '15 at 08:12

0 Answers0