programming-examples/js/Array/Write a JavaScript function to find an array contains a specific element..js

10 lines
251 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function contains(arr, element) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === element) {
return true;
}
}
return false;
}
arr = [2, 5, 9, 6];
console.log(contains(arr, 5));