Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

avaScript slice() With Negative index

Negative Index Slice in JavaScript
let programmingLangs = ["JavaScript", "Python", "C#", "Java", "PHP", "Node"];

// Slice the last 4 elements in an array
let arr1 = programmingLangs.slice(-4)
console.log("Last 4 elements will be sliced", arr1)

//Slice array from index start to second last
let arr2 = programmingLangs.slice(1, -1)
console.log("Array will be sliced from Index 1 to second last", arr2) //Note the end is -1 and that index will not be sliced
Source by itsjavascript.com #
 
PREVIOUS NEXT
Tagged: #avaScript #With #Negative #index
ADD COMMENT
Topic
Name
9+1 =