Arrays: ======= Collection of similar data items. [1,3,5,7,9] ==> Number array [1,1.2,2.3,123] ["a", "b", "c"] Array Definition: ================= 2-ways: 1) Literal Form ================ Syntax: let/var/const name-of-array = [elements/items with comma separation] const a = [] let b = [1,2,3,4,5,6] var c = ['a','b','c'] console.log(typeof a) console.log(typeof b) console.log(typeof c) a = [[1,3,5],[7,9,11],[2,4,6],[8,10,12]] console.log(a) 2) Object Form ============== ==> class for the Array ==> "Array" ==> using "new" keyword/operator we can create an object for the class "Array" ==> Array Object Syntax: let/var/const name-object = new Array(elements with comma) let a = new Array(10,20,30,40) // classname objname = new classname(); console.log(a) console.log(typeof a) Multi-dimensional Array: ======================= a = new Array([1,3,5,7,9],[2,4,6,8,0]) console.log(a) =============================================== Indexing: ========= [] // accessing individual elements of array ==> indexing a = [1,3,5,7,9] // 1d-array b = [[1,2,3,4],[5,6,7,8]] // 2d-array c = [[[1,2,3],[4,5,6],[7,8,9]],[[0,2,4],[6,8,10],[1,3,5]]] // 3d-array console.log(a[0]) console.log(a[1]) console.log(a[2]) console.log(a[3]) console.log(a[4]) console.log(b[0]) console.log(b[1]) console.log(b[0][0],b[1][0]) console.log(b[0][1],b[1][1]) console.log(b[0][2],b[1][2]) console.log(b[0][3],b[1][3]) console.log(c[0]) console.log(c[1]) console.log(c[0][0]) console.log(c[0][1]) console.log(c[0][0][0]) ========================================= WAP TO PRINT THE LAST ELEMENT OF THE ARRAY. =========================================== array-name.length - 1 ================================================= Mutability: =========== a = new Array(10,20,30,40) b = [10,20,30] console.log(a) console.log(b) a[1] = -20 b[1] = -20 console.log(a) console.log(b) ================================= push(): ======= ==> can be used to add element at the end of the array. Syntax: array-name.push(element) a = new Array(10,20,30,40) console.log(a) a.push(50) console.log(a) ============================== unshift(): ========== ==> can be used to add the element at the beginning of the array. Syntax: array-name.unshift(element) a = new Array(10,20,30,40) console.log(a) a.push(50) console.log(a) a.unshift(0) console.log(a) ================================ splice() ======= ==> can add element at the specified index Syntax: a.splice(index, element) ======================================= pop() a = new Array(10,20,30,40) console.log(a) a.pop() console.log(a) a.shift() console.log(a) a.splice(1) console.log(a) ========================================== 1) WAP IN JS TO FIND THE SECOND LARGEST ELEMENT FROM THE ARRAY. 2) WAP IN JS TO FIND THE LENGTH OF THE ARRAY WITHOUT BUILT-IN METHOD. 3) WAP IN JS TO REVERSE THE ARRAY.