// ch08-arrays--splice.js


'use strict';


// ADDING OR REMOVING ELEMENTS AT ANY POSITION
// SPLICE


// The first argument is the index you want to start modifying
// The second argument is the number of elements to remove (use 0 if you don’t want to remove any elements)
// The remaining arguments are the elements to be added

const arr = [1, 5, 7];
console.log(`arr: \t${arr}\tlength: \t${arr.length}`);	
// arr: 	1,5,7	length: 	3

const arr1 = arr.splice(1, 0, 2, 3, 4);
console.log(`arr: \t${arr}\tlength: ${arr.length}\tarr1: \t${arr1}\tlength: ${arr1.length}`);	
// arr: 	1,2,3,4,5,7	length: 6	arr1: 	[]	length: 0


const arr2 = arr.splice(5, 0, 6);
console.log(`arr: \t${arr}\tlength: ${arr.length}\tarr2: \t${arr2}\tlength: ${arr2.length}`);	
// arr: 	1,2,3,4,5,6,7	length: 7	arr2: []		length: 0

const arr3 = arr.splice(1, 2);
console.log(`arr: \t${arr}\tlength: ${arr.length}\tarr3: \t${arr3}\tlength: ${arr3.length}`);	
// arr: 	1,4,5,6,7	length: 5	arr3: 	2,3	length: 2


const arr4 = arr.splice(2, 1, 'a', 'b');
console.log(`arr: \t${arr}\tlength: ${arr.length}\tarr4: \t${arr4}\tlength: ${arr4.length}`);	
// arr: 	1,4,a,b,6,7	length: 6	arr4: 	5	length: 1