/////////////////*********ARRAYS IN JS*********/////////////// const arr =[0,1,2,3,4,5] const heros = ["srk","sk", "akki"] console.log(arr[1]); const arr2 = new Array(1,2,3,4,5,5) console.log(arr2[1]); ////////// array methodss///////////////////// arr.push(6) /// adding elements in array arr.push(7) console.log(arr); arr.pop()/// remove last element in array console.log(arr); arr.unshift(9) //// adding at first console.log(arr); arr.shift() //// removed 9 console.log(arr); console.log(arr.includes(9));/// boolean outcomes console.log(arr.indexOf(2));/// index at prsented elemensted const newArr = arr.join() console.log(newArr);/// prints without square braces console.log(typeof newArr); /// changes number into string beacuse we used join() method //////// slice method console.log("a" , arr); const myn1 = arr.slice(1,3) // 1 and 2 will be printed console.log("after slicing ",myn1); console.log("original copy will be same as a " , arr); ///////splice method const myn2 = arr.splice(1,3) // 1 , 2 and 3 will be printed console.log("after splicing ",myn2); console.log("splice elements will be deleted " , arr); ///it will deleted the splice part //// inportant for interview question !!!!!!!!!!! /* the difference bw slicing and splicing slicing - will print 1 less than the final index and not effect the orginal copy.. spkicing - will print all the elements and delete all spliced elements from the original array*/
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter