Skip to main content

Posts

Showing posts with the label inarray

wired output of the combination of $.each and jQuery.inArray function

My complete code: jQuery.extend({ combinationCheck: function (p1position) { var Combination = [1, 2, 3, 4, 5, 6, 7, 8]; Combination[0] = [1, 2, 3]; Combination[1] = [4, 5, 6]; Combination[2] = [7, 8, 9]; Combination[3] = [1, 4, 7]; Combination[4] = [2, 5, 8]; Combination[5] = [4, 6, 8]; Combination[6] = [1, 5, 9]; Combination[7] = [3, 5, 7]; $.each(p1position, function (index, value) { var num = value; if ($.inArray(String(value), Combination[1]) != '-1') { alert("there"); } else { alert("not there"); } }); }); so it works. If I were to set num to 5, it alerts "is there", and for 8 --> "not there". but the problem is I have another array. p1position = [1,5]; and go through the array.. $.each(p1position,function(index,value){ var num = value; //then call the jQuery.inArray function as written above, it always return not

wired output of the combination of $.each and jQuery.inArray function

My complete code: jQuery.extend({ combinationCheck: function (p1position) { var Combination = [1, 2, 3, 4, 5, 6, 7, 8]; Combination[0] = [1, 2, 3]; Combination[1] = [4, 5, 6]; Combination[2] = [7, 8, 9]; Combination[3] = [1, 4, 7]; Combination[4] = [2, 5, 8]; Combination[5] = [4, 6, 8]; Combination[6] = [1, 5, 9]; Combination[7] = [3, 5, 7]; $.each(p1position, function (index, value) { var num = value; if ($.inArray(String(value), Combination[1]) != '-1') { alert("there"); } else { alert("not there"); } }); }); so it works. If I were to set num to 5, it alerts "is there", and for 8 --> "not there". but the problem is I have another array. p1position = [1,5]; and go through the array.. $.each(p1position,function(index,value){ var num = value; //then call the jQuery.inArray function as written above, it always return not