//1
var ar=[1,2,3,4,5,6,7];
ar.length=3;
console.log(ar);
//2
var ar=[1,2,3,4,5,6,7];
delete ar[3]; // index will be undefined
console.log(ar);
//3
ar.pop();
console.log(ar);
//4
ar.shift();
console.log(ar);
//5
var ar=[1,2,3,4,5,6,7];
ar.slice(3,5);
console.log('slice 3 to 5',ar.slice(3,5));
console.log(ar);
//6
var ar=[1,2,3,4,5,6,7];
console.log('splice 3 to 5',ar.splice(3,5));
console.log('splice 3',ar.splice(3));
console.log('slice 3',ar.slice(3));
console.log(ar);
/*
https://stackoverflow.com/questions/37601282/javascript-array-splice-vs-slice
The splice() method returns the removed item(s) in an array and slice() method returns the selected element(s) in an array, as a new array object.
The splice() method changes the original array and slice() method doesn’t change the original array.
The splice() method can take n number of arguments and slice() method takes 2 arguments.
*/
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.