programming-examples/js/Array/Write a JavaScript function to find an array contains a specific element..js
2019-11-15 12:59:38 +01:00

10 lines
251 B
JavaScript

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));