Arrays Part-04: ============== How to Remove elements from an array: ===================================== 1) pop(): ========= ==> can use to remove/return the last element of an array Ex: [10,20,30,40] pop() ==> 40 Syntax: array-name-object.pop() let a = [100,true,'A','R','B','JavaScript',2000,2024] console.log("The Given array = "); console.log(a); var return1 = a.pop() console.log("The Array after the pop operation is = "); console.log(a); console.log("The Returned value = ",return1); console.log("The Returned Value = ",a.pop()); console.log("The Array after the pop operation is = "); console.log(a); How to understand the return value of the given pre-defined function? ====================================================================== two ways: 1) use the function call to the variable and print that variable. 2) directly define the function call in print methods like: log(), write() etc. Note: ===== using pop(), we cannot remove the specified element and also not possible to remove more than one element. let a = [100,true,'A','R','B','JavaScript',2000,2024] console.log("The Given array = "); console.log(a); a.pop(true,100,'A'); console.log("The Array after the delete operation is = "); console.log(a); ==================================================================== 2) shift(): =========== ==> can use to remove/return the first element of an array. Syntax: array-name.shift(); let a = [100,true,'A','R','B','JavaScript',2000,2024] console.log("The Given array = "); console.log(a); // shift operation console.log("The Deleted Element = ",a.shift()); // 100 got removed console.log("The Array after the shift operation is = "); console.log(a); console.log("The Deleted Value = ",a.shift()); // true can be removed console.log("The Array after the shift operation is = "); console.log(a); a.shift('ABC','R','B'); console.log(a); ========================================================= 3) splice(): ============ Syntax: array-name.splice(index, count); let a = [100,true,'A','R','B','JavaScript',2000,2024] console.log("The Given array = "); console.log(a); a.splice(2,0); console.log(a); a.splice(2,3); console.log(a); ==================================================================== Sorting of array elements: ========================== Ecommerce application: cart at 6am ==> p1 at 6.28 am ==> p2 at 7.30 ==> p3 at 7.56 ==> p4 ==> sorting ===> arranging of elements in ascending or descending order. 1) sort(): ========= ==> sorting in ascending order by default. Syntax: array-name.sort() 2) reverse(): ============== ==> to reverse the array. Syntax: array-name.reverse() let a = [100,true,'A','R','B','JavaScript',2000,2024] console.log("The Given array = "); console.log(a); a.sort() console.log("The Array after the sorting is (Ascending Order)= "); console.log(a); (a.sort()).reverse(); console.log("The Array after the sorting is (Descending Order)= "); console.log(a); Assignment: =========== WAP in javascript, to add new element into the dropdown and also remove the first dropdown option. Ex: Dropdown: Electronics Fashion Grosessories Beauty products into this: want to add: Laptops & Mobiles and remove: Electronics ==============================================================================