Linked Questions
365 questions linked to/from How do I check if an array includes a value in JavaScript?
1406
votes
18
answers
1.8m
views
Determine whether an array contains a value [duplicate]
I need to determine if a value exists in an array.
I am using the following function:
Array.prototype.contains = function(obj) {
var i = this.length;
while (i--) {
if (this[i] == obj)...
811
votes
9
answers
1.6m
views
Check if an element is present in an array [duplicate]
The function I am using now to check this is the following:
function inArray(needle,haystack)
{
var count=haystack.length;
for(var i=0;i<count;i++)
{
if(haystack[i]===needle){...
840
votes
8
answers
1.2m
views
Best way to find if an item is in a JavaScript array? [duplicate]
What is the best way to find if an object is in an array?
This is the best way I know:
function include(arr, obj) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == obj) return ...
269
votes
18
answers
606k
views
How to determine if object is in array [duplicate]
I need to determine if an object already exists in an array in javascript.
eg (dummycode):
var carBrands = [];
var car1 = {name:'ford'};
var car2 = {name:'lexus'};
var car3 = {name:'maserati'};
var ...
214
votes
16
answers
347k
views
JavaScript is in array [duplicate]
Let's say I have this:
var blockedTile = new Array("118", "67", "190", "43", "135", "520");
There's more array elements but those are just few for readability purposes. Anyways, I could do a "for" ...
299
votes
5
answers
643k
views
How to check if a string array contains one string in JavaScript? [duplicate]
I have a string array and one string. I'd like to test this string against the array values and apply a condition the result - if the array contains the string do "A", else do "B".
How can I do that?
69
votes
5
answers
265k
views
Jquery, checking if a value exists in array or not [duplicate]
I believe this question will be fairly easy for the ones who played around with java script / jquery.
var arr = new Array();
$.map(arr, function() {
if (this.id == productID) {
this.price = ...
67
votes
9
answers
54k
views
Test for value in Javascript Array [duplicate]
In SQL Server, I could say:
WHERE X IN(1,2)
How would you rewrite the following in JavaScript:
if (X==1 || X==2) {}
65
votes
8
answers
59k
views
JavaScript: Simple way to check if variable is equal to one of two or more values? [duplicate]
Is there an easier way to determine if a variable is equal to a range of values, such as:
if x === 5 || 6
rather than something obtuse like:
if x === 5 || x === 6
?
72
votes
3
answers
347k
views
Check if value exists in the array (AngularJS) [duplicate]
Currently, I'm using the forEach()-method of angular to check the new value with the array of objects. But that's the wrong approach because, for example, in the list are 20 objects. When I'm creating ...
40
votes
3
answers
102k
views
Javascript - check array for value [duplicate]
I have a simple array with bank holidays:
var bank_holidays = ['06/04/2012','09/04/2012','07/05/2012','04/06/2012','05/06/2012','27/08/2012','25/12/2012','26/12/2012','01/01/2013','29/03/2013','01/04/...
23
votes
7
answers
62k
views
Find out if a variable is in an array? [duplicate]
I have a variable:
var code = "de";
And I have an array:
var countryList = ["de","fr","it","es"];
Could someone help me as I need to check to see if the variable is inside the countryList array - my ...
39
votes
3
answers
58k
views
Javascript if in x [duplicate]
Possible Duplicates:
Test for value in Javascript Array
Best way to find an item in a JavaScript Array ?
Javascript - array.contains(obj)
I usually program in python but have recently started ...
15
votes
2
answers
67k
views
javascript, jQuery - check if value exists in array [duplicate]
Is there a better way to check multiple items match a variable in if statement
I have 3 if statements and i need to see if a item matches an array/variable named code. There are a lot of items to ...
22
votes
9
answers
17k
views
how can I compare a string with several values? [duplicate]
Possible Duplicate:
array.contains(obj) in JavaScript
Something like:
if (mystring == "a" || mystring == "b" || mystring =="c")
I was hopping to do:
if (mystring in ("a", "b", "c"))
is it ...