Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery serialize form data and submit 
Javascript :: Print a number with commas as thousands separators in JavaScript 
Javascript :: js wrap an element 
Javascript :: bootstrap datetimepicker onchange event 
Javascript :: npm install the exact package version specified in package.json 
Javascript :: nuxt 18 mountend route push 
Javascript :: javascript capitalize first letter 
Javascript :: yarn react-native-async-storage 
Javascript :: react native get numeric random string length of 5 characters 
Javascript :: react data attributes event 
Javascript :: js json download 
Javascript :: local storage check max size 
Javascript :: trigger event javascript 
Javascript :: How to remove text from a string in javscript 
Javascript :: javascript one off event listener 
Javascript :: js delete element by id 
Javascript :: get distance of element from top of page javascript 
Javascript :: javascript auto scroll down slowly 
Javascript :: javascript friendly number format with commas 
Javascript :: express get jwt token from header 
Javascript :: how to check if a number is float javascript 
Javascript :: deep clone array in javascript 
Javascript :: typescript round 
Javascript :: jquery get child div 
Javascript :: scrollto element by id center 
Javascript :: javascript number to words 
Javascript :: leap year condition in javascript 
Javascript :: viewdata array mvc razor javascript 
Javascript :: mongoose string index 
Javascript :: javascript scp in to array 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =