Can I find a required name without loop through each array item? Is there any faster way to do the same assuming that I have a very big array length, because if I have an array of 10000 items and the name doesn't exist in it, it will be a waste of time and assuming that we don't have inclouds function
$(document).ready(function() {
function binarySearch(names, requiredName) {
for (var i = 0; i < names.length; i++) {
if (names[i] === requiredName) {
return true;
}
}
return false;
}
console.log(binarySearch(['ola', 'amer', 'anwar', 'mamon'], 'hadeel'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>