Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to show only few first elements of array js

const longArray = [1, 2, 3, 4, 5, 6, 7]
// to show only first 4 elements
const shortArray = longArray.slice(0,4) // slice(startIndex, numberOfSteps)

console.log(longArray) // [1, 2, 3, 4, 5, 6, 7]
console.log(shortArray) // [1, 2, 3, 4]
 
PREVIOUS NEXT
Tagged: #show #elements #array #js
ADD COMMENT
Topic
Name
6+2 =