array index javascript show only first 2 elements

JavaScript
array.slice(0, n);
Source

Also in JavaScript: