COntinuining Day 4. Arrray (25th May). => Array in a non-primitive data types. => It is used to store nultiple items under a single varible. => 18:25 slice() does not manupulate main array. => splice() manupulate original array. THANK YOU SIR JI .
SUMMARRY: 1. Array is written in brackets [ ]. 2.Array data type is an object. 3.Array can contain different data types . i.e string,number,boolean,array etc. 4. Array is zero based indexing. It starts with zero. 5. Once changed its original value will also change beacause it is non primitive (refrence) type. ARRAY METHODs : 1.Push = adds value to last of an array. 2. Pop = removes last value of an array. 3. Unshift = adds value at first of an array. 4.Shift = removes first value of an array. 5. Includes = checks true or false. 6. IndexOf = checks the position of value in number form. 7.Join = converts to string. 8. Slice(value to remove from,value remove upto but don't include)= returns new array and original value remains unchanged. Use when you need to extract a portion of an array without modifying it. 9. Splice(value to delete from, number of value to delete) = returns new array with deleted one and original value changed.Use when you need to add, remove, or replace elements within an array.
actually there is a mistake in splice method....splice not includes last index value but it takes number of values given from starting index.....for ex: arr = [2,3,4,5,6,7,8,9] and then console.log(arr.splice(3,4)); gives 5,6,7,8.....however thank u so much hitesh sir for such valuable series...you are my favourite teacher
Thank you so much, sir, for your fantastic explanation of Arrays. Your 18-minute video was extremely insightful, but I must say, I spent about 1 to 1.5 hours practicing along. I also made it a habit to glance at my notes every day. Thanks to your wonderful guidance, I now have a solid grasp of Arrays. I am truly grateful for your efforts. Honestly, your teaching style is so engaging that it sparks my enthusiasm for learning and programming. I have already charted my learning path. Once again, thank you, Sir. Your teaching is truly remarkable and greatly appreciated.
Hello Sir, I am no one to make you correct . But I think Splice( ) method is used to perform insertion, deletion and updation. Eg:- myArr( a, b , c) Here, a = starting index b = number of elements to be deleted c = elements to be deleted. For eg:- const myArr = [ 10, 20, 30, 40, 50]; myArr.splice(1, 3); console.log(myArr); So here, a= 1 and b= 3. So it will start from index 1 and remove 3 elements. So, the output will be [10, 50]. Because it removed the 3 elements from index 1 i.e. [20, 30, 40] Now, In other example, const myArr = [ 10, 20, 30, 40, 50]; myArr.splice(1, 3, 60); console.log(myArr); Here, a= 1 , b= 3 and c= 60 So it will start from index 1 and remove 3 elements and then insert 60 at the place of removed elements. So, the output will be [10, 60, 50]. Because it removed the 3 elements from index 1 i.e. [20, 30, 40] and then inserted 60 at the place of removed elements.. My intention was not to spread any hatred.. I am your fan.. the way you teach us and makes coding this much simple for us is really appreciable.😍❤️ Your explaination is too good.. You are really a Brilliant Teacher.. ❤️❤️🔥
Yes, thanks for more detail explanation. In addtion, the var "C" you are denoting, i.e. "c = elements to be deleted.', I guess the better definition would be like 'The elements to add to the array' , as the third or onwards parameter are the items to be added to the original array / replace the deleted item. 🙂🙂😊😊
yes you are right also in documentation written = Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
thank you sir I am learning web and from where i have learned they have finished whole js in 3 days 😅 and now i am learning from your videos or previous channel videos. thank you
Also Splicing with starting index 0 will not consider last index same as slice operation but it will consider last index for any starting index greater than 0. (at 16:46)
(18:25) **Note** splice() doesn't works like slice(start, end) as it does not have parameters like "start and end" . start : starting index of the elements to be sliced. end : ending index of the elements to be sliced. Syntax of splice():- splice(start, deleteCount) Here, start : starting index from where to slice in array deleteCount : How many Elements you want to delete in the array (count of the elements to be removed) So , slice() and splice() both are also different in working along with Manipulation of Original Array.
Helli Sir, ur videos hv been incredibly helpful n engaging for me in my learning journey. The way u explain complex topics with clarity n provide valuable insights truly sets your content apart. ur dedication to creating high-quality study materials is evident, n I'm grateful for the effort you put into each video. I've found ur content to be a valuable resource dat has greatly contributed 2 my understanding of the subjects u cover. Thank u for ur hard work n commitment to education. Looking forward to more of ur fantastic content in the future!
I just got to know a new thing, myArray.splice(3,4); it means start splicing myArray at index 3 for the count of 4 elements. It does not means start at 3rd index till 4th. Hope that helps!
17:25 The statement that the last index is also included while using splice is incorrect. Splice has second parameter which mentions delete count - number of elements to be deleted after start. So, A = [1,2,3,4,5] A.splice(2,3) will give output as [1,2]
Amazing video quality, sound quality, eye soothing background and content is the king. I just love all your videos, you made my developer journey enjoyable.
splice(0, 3) include indexes 0, 1, 2 (not 3) splice(1,3) include indexes 1, 2, 3 (3 included) 3 is not the end index, it is the number of elements to be deleted after index mentioned as the 1st argument
Hello hitesh sir just want add something in splice that (1,3) is nothing but (start, delete count, element1,etc) after deleting you can also add value or element
=> Slice(start index, last index[not included] ) // return specific portion of the array original array don't manipulated remain same basically it creates a shallow copy of original array => Splice (start index, last index [included] ) // removes specific part of from original array and manipulate it
sir bohat acha bolte hain ap , ap agar movies me kam krein to is se zada hit ho skte hain by the way me pakistan Lahore se hon ak industry me kam krta hon agr ap mere comment ka jwab dein gy to acha lgy ga
Sir, I appreciate the content. However, the main difference between 'slice()' and 'splice()' wasn't entirely clear. In 'slice()', the first argument sets the start index, and the second sets the end index for slicing. In 'splice()', the first argument is the start index for removing/adding elements, and the second specifies the number of elements to remove. Thank you for your explanation.
Hey everyone, a huge shoutout to Hitesh Choudhary💖 for the incredible tutorials on this channel. Subscribe now to show your appreciation and gain access to these priceless resources without spending a dime!
if we declare variable with const that means we cannot change or update value then when we declare a variable like const array1=[1,2,4] .HERE WE CAN CHANGE VALUE IN ARRAY THEN HOW IT IS const
wow Awesome, you covers everything. I love the quality of the content you served, I will keep commenting, I really want your channel growth as it is really helpful for deep understanding. Your content needs lots of patience to learn
My notes of this video: // Array can be a group of mixed datatypes. It may include number, string or anther array too // It has zero based indexing. // arrays are resizable // the last element is at the value of the array's length property minus 1. // JavaScript array-copy operations create shallow copies. // A shallow copy (original copy) of an object is a copy whose properties share the same references (point to the same underlying values) // A deep copy (duplicate copy) of an object is a copy whose properties do not share the same references // Array is always defined under [] let arr = [1,2,"pranjal",true,5];// is same as let arr_ = new Array(1,2,3,4); // to add elements arr.push(6); console.log(arr); //to delete last value arr.pop(); console.log(arr); // To insert elements at the start. but it is not good as all the elements get shifted increasing the load arr.unshift(10); console.log(arr); // To delete elements at the start arr.shift(); console.log(arr); // Does it include the specified element. Returns boolean console.log(arr.includes(56)); // Index of element that does'nt exist is -1 console.log(arr.indexOf(90)); // Most important interview question: difference betn slice and splice let Myarr = [1,2,3,4,5]; console.log("A ",Myarr);// The original array let slice = Myarr.slice(1,3);// slices out element from 1 to 2 excluding 3 and original array remains same console.log(slice); // After slicing console.log("B ",Myarr); let splice = Myarr.splice(1,3);// splices out elements permanently from 1 to 3 including 3 too and manipulates the original array console.log(splice); // after splicing console.log("C ", Myarr);