Checking whether a value exists in an array javascript
const fruits = ['apple', 'banana', 'mango', 'guava'];
function checkAvailability(arr, val) {
return arr.some(arrVal => val === arrVal);
}
checkAvailability(fruits, 'kela'); // false
checkAvailability(fruits, 'banana'); // trueprivate boolean ZitAlInArray(int value, List<Integer> list) {
return array.indexOf(value) > -1;
}
private boolean zitAlInArray(int[] array, int index) {
for (int i = 0; i < index; i++) {
if (array[i] == array[index]) {
return true;
}
}
return false;
}
Also in JavaScript:
- javascript ajax request
- javascript advanced interview questions
- how to appendChild in the begin of the div javascript
- graphql custom JSON scalar type
- Parallax.js wrapper for react
- how to convert seconds into days hours seconds js
- react native margin vs padding
- js this returns undefined
- documenting functions javascript
- javascript .foreach
- react mui icons
- js shortcut
- stop a video jquery
- vs code how separate one line to multilines
- webpack react proxy not working
- how to create a variable in javascript
- how to print to screen in javascript
- use .map to count length of each element in an array
- extract data from pdf nodejs
- string to char array in javascript
- javascript redirect button
- span role link
- how to create tab component in jquery
- mongoose find and update prop