JSFiddle - React, Tailwind, and code Playground

by masaab algailani

JavaScript

var houseArray = ["house", "door", "lock", "window", "toilet"];

//slice an array and from start index to end index and return a array
var partofHouseArray = houseArray.slice(1,4);
for(var i=0;i < partofHouseArray.length; i++){
    alert("slice items:" + partofHouseArray[i]);
}
    

//add element in the array at the end
 alert(houseArray.push("bedroom"));
for(var i = 0; i < houseArray.length; i++){
    alert("Inserted items: "+ houseArray[i]);
}
//pop delete last element and return last element
alert("removed Item:" + houseArray.pop());


//shift remove and returns first element in the array
alert("element removed:"+ houseArray.shift());