Q:

Write a JavaScript program to get the nth element of an given array

0

Write a JavaScript program to get the nth element of an given array. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const nthElement = (arr, n = 0) => (n > 0 ? arr.slice(n, n + 1) : arr.slice(n))[0];
console.log(nthElement(['a', 'b', 'c'], 1));
console.log(nthElement(['a', 'b', 'b'], -3));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now