Мне нужно сравнить динамически создаваемую переменную с массивом значений c. Поскольку переменная генерируется динамически, я не могу сделать что-то вроде
if ($.inArray('example', myArray) != -1)
{
// found it
}
Пока у меня есть это
//This runs for each link in the .lc_Cell element
$('.lc_Cell > p > a').attr('href', function(i, href) {
//Grab the link and split it into chunks at each occurence of '&'
var arr = href.split('&');
console.log(arr);
//Keep a portion of the link as a var, this is always a 4 digit number
//For the purposes of this question lets say this value is going to be 7473
var trId = arr[1].slice(-4);
console.log(trId);
//Populating my array of desired numbers to search against
var validTR = [7473, 7474, 7475, 7476, 7477, 7478, 7479, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7487, 7488, 7489, 7490, 7491, 7492, 7493, 7494, 7495, 7351];
console.log(validTR);
//Compare the sliced value from the link against the array
var testingID = $.inArray(trId, validTR)
console.log(testingID);
}
Мой testingID в консоли постоянно возвращает -1, даже если значение в trId содержится в массиве.
В конечном счете, мне нужно иметь возможность получить положительное значение для testingID, чтобы я мог написать оператор if, чтобы потом что-то делать.