Linked Questions

5002 votes
63 answers
3.7m views

What is the most concise and efficient way to find out if a JavaScript array contains a value? This is the only way I know to do it: function contains(a, obj) { for (var i = 0; i < a.length; i++...
brad's user avatar
  • 75.8k
3 votes
3 answers
5k views

I want to make a filter. Where if you input a word that is in the 'blacklist' it will tell something. I've got all the code but have a problem. JS: input = document.getElementById("input").value; ...
Roy Berris's user avatar
  • 1,602
2 votes
1 answer
222 views

I want to be able to see if "megan" is a part of the array people. Though, i can only do this by using people[2]. Here is my code: var people = new Array("jack","ian"); document.write(people[0]); ...
igetstuckalot's user avatar
840 votes
8 answers
1.2m views

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 ...
zimbatm's user avatar
  • 9,408
286 votes
21 answers
373k views

Is there a way in JavaScript to compare values from one array and see if it is in another array? Similar to PHP's in_array function?
roflwaffle's user avatar
  • 30.8k
7 votes
3 answers
67k views

I have the following JSON data. categories = [ {catValue:1, catName: 'Arts, crafts, and collectibles'}, {catValue:2, catName: 'Baby'}, {catValue:3, catName: 'Beauty and fragrances'}, {...
Kiran Shahi's user avatar
  • 8,000
0 votes
4 answers
40k views

I have an object like: item: { b: null c: "asd" i: 10 q: 10 s: Array [237,241]} Also I have an array of ids: var ids = [237, 238, 239, 240, 242, 243...] I dont know how to check ...
wezeweze's user avatar
  • 131
3 votes
3 answers
21k views

I have an array of values with names: names = ['Jim', 'Jack', 'Fred'] I have also received a value from a function, which is a name in string form, such as: returnedValue = 'Jim' How can I run the ...
Anthony's user avatar
  • 14.5k
-1 votes
5 answers
708 views

I want to detect if a user types one of the strings of my list and then output in what string the user typed in the console. HTML <input id="input"></input> JS window.onload = function()...
Tim's user avatar
  • 195
3 votes
2 answers
123 views

There is a way to lower the sensibility of the indexOf? Like this var arr = ["Hello", "stackoverflow"] var idx = arr.indexOf("stack") And get idx = 1 instead of idx = -1
urco's user avatar
  • 189
3 votes
3 answers
143 views

Hello, I'm trying to make a simple matching game in javascript. If the the user inserts the text president goes crazy in any way that contains every strings in word_tmp, then the word_tmp becomes ...
Adam Ramadhan's user avatar
-2 votes
2 answers
113 views

I have a JavaScript programme that randomly selects an image of an object from the database and display that image to the user. The image is saved with the object name (i.e. apple.gif) I am using the ...
james's user avatar
  • 1