const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
// expected output: 1
// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output: 4
console.log(beasts.indexOf('giraffe'));
// expected output: -1
function quickCheck(arr, elem) {
if (arr.indexOf(elem) >= 0) {
return true;
}
return false;
}
console.log(quickCheck(["squash", "onions", "shallots"], "mushrooms"));
function quickCheck(arr, elem) {
return arr.indexOf(elem) >= 0 ? true : false;
}
console.log(quickCheck(["squash", "onions", "shallots"], "mushrooms"));
function quickCheck(arr, elem) {
return arr.indexOf(elem) != -1;
}
console.log(quickCheck(["squash", "onions", "shallots"], "mushrooms"));
let fruits = ['Apple', 'Banana']
let first = fruits[0]
// Apple
let last = fruits[fruits.length - 1]
// Banana
Index Javascript