Answers for "index an array in javascript"

2

js array index

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
Posted by: Guest on August-13-2021
2

access index of array javascript

let first = fruits[0]
// Apple

let last = fruits[fruits.length - 1]
// Banana
Posted by: Guest on February-17-2020

Code answers related to "index an array in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language