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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
function include(arr, obj) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] == obj) return true;
}
}
console.log(include([1, 2, 3, 4], 3)); // true
console.log(include([1, 2, 3, 4], 6)); // undefinedWhat 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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
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 true;
}
}
console.log(include([1, 2, 3, 4], 3)); // true
console.log(include([1, 2, 3, 4], 6)); // undefinedPossible Duplicate:
array.contains(obj) in JavaScript
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
Possible Duplicate:
array.contains(obj) in JavaScript
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
- 2.7k
- 5
- 33
- 45
Best way to find if an item is in a JavaScript array?
Best way to find if an item is in a JavaScript array?
Possible Duplicate:
array.contains(obj) in JavaScript
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
Best way to find an item in a JavaScript array?
Possible Duplicate:
array.contains(obj) in JavaScript
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
Best way to find if an item is in a JavaScript array?
Possible Duplicate:
array.contains(obj) in JavaScript
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 true;
}
}
include([1,2,3,4], 3); // true
include([1,2,3,4], 6); // undefined
- 31.3k
- 22
- 110
- 134