How to access an array item using the index position in JavaScript

1 Answer

0 votes
let arr = ['javascript', 'c++', 'php'];

let first = arr[0];
console.log(first);

console.log(arr[1]);
console.log(arr[2]);
console.log(arr[3]);


let last = arr[arr.length - 1];
console.log(last);


    
    
/*
run:
    
"javascript"
"c++"
"php"
undefined
"php"
    
*/

 



answered Nov 28, 2020 by avibootz

Related questions

2 answers 274 views
3 answers 286 views
1 answer 186 views
1 answer 219 views
1 answer 206 views
...