by @kodeazy

How to get middle element of an array in javascript?

Home » javascript » How to get middle element of an array in javascript?
var arry = ['element_1', 'element_2', 'element_3', 'element_4', 'element_5','element_6']
  • I have an array of elements as above.
  • we use length method to get the length of the array.
  • we divide the length of the array by2 to get the middle element of the array.

    arry[(arry.length/2)-1];

    Output

    'element_3'