

To get the third element of this array (which has an index of 2), you can use the following code: const thirdElement = arr.slice(2, 3) Īlternatively, you can use the () method to get the element that meets a certain condition. To find the nth element of an array in JavaScript, you can also use the () method to get a subarray containing the element you want, and then access the first element of the subarray.įor example, consider the following array: const arr = The following example get the 3rd item from a JavaScript array.

For example, if you want the 3rd item of any array, you will get the item at index 2, i.e., 3-1.

That means, the first item of an array is at 0th position. To find the nth element of an array in JavaScript, you will get the element at n-1 position in the array. An array in JavaScript starts at 0th index.
