how to get first 4 elements of array in javascript code example Example: array index javascript show only first 2 elements array.slice(0, n);