Slice and Splice in Javascript

preview_player
Показать описание
Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.

All the learning resources such as code files, documentations, articles and community discussions are available on our website:

You can find our discord link, github link etc on the above website.

Рекомендации по теме
Комментарии
Автор

Full course is FREE and will be available here

HiteshCodeLab
Автор

The most important difference between splice and slice is that splice changes the actual array while slice creates a new copy of the array.

haythamkenway
Автор

Sir the way you teach is FANTABULOUS. I am a developer with 7 years of experience, and still used to get confused with so many things in JS. But your videos have just helped me understand in the most simple way possible. THANK YOU SO MUCH.!! Best part is you belong from the same state that I do and that somewhere makes me feel proud too. LOVE YOU SIR.!! And THANK YOU AGAIN A LOT.!!!

tasneemkhilonawala
Автор

I was very confused in Slice and splice now this concept is clear sir, Thank you, great js series forever ❤️

gopalukani
Автор

1:17 This is year 2020 and this raises a lot of Questions

piyushmahapatra
Автор

Hello Hitesh Sir, i have problem in understabnding slice & splice when start & end range comes up with negative number. it will be more helpful if you make a video on same

creativegeeks
Автор

This might be the first YouTube video I've ever commented on. I'm taking a JS class right now and your explanation of splice would have saved me hours of frustration if I had seen it earlier. Thank you!

ianmcdonald
Автор

hi
splice function cant be written inside a console.log ??
i tried both here's what i tried -

const arr1 = ["a", "b", "c", "d", "e", "f"];
console.log(arr1.splice(1, 4, "HI"));

output = [ 'b', 'c', 'd', 'e' ]

const arr1 = ["a", "b", "c", "d", "e", "f"];
arr1.splice(1, 4, "HI");
console.log(arr1);

output = [ 'a', 'HI', 'f' ]



What's the difference ?

arpitnigam
Автор

Splice alters the original array right whereas slice doesnt ?

ananyasharma
Автор

Hi Hitesh, thank you for creating this awesome playlist on js. I have a question, why console.log(user.splice(1, 2, "Hello", "Hi")) is not working as expected?
Correct me if I am doing something wrong. Thanks

dajindersingh
Автор

Where we use splice function in real life programs??

shubhamverma
Автор

When you teach everything becomes so easy! thank you sir :)

akansha
Автор

referring splicing at timestamp 6:15
console.log(users.splice(1, 3, "HI");
result: ['Tim', 'Ton', 'Sam']

I am not sure, but does it somehow related to the context / global scope? if so, please explain.

adnanabbasi
Автор

Just tried out that if not given any values after the delete count, 'slice' and 'splice' give complementary results! :-D
var users = ['Ted', 'Tim', 'Ton', 'Sam', 'Sor', 'Sod']
console.log(users.slice(0, users.length-3));
//[ 'Ted', 'Tim', 'Ton' ]
users.splice(0, users.length-3)
console.log(users); //[ 'Sam', 'Sor', 'Sod' ]

ameyabhave
Автор

@Hitesh Choudhary

One more difference between slice and splice i.e. slice does not have side effect and splice does have side effect. It means slice will create new array from existing array and splice will change the existing array. am I right sir?

rmaheshchalke
Автор

Sir can u please explain why
users.splice(1, 4, "HI");
console.log(users);

and
console.log(users.splice(1, 4, "HI'));
works differently ?

tanishbajpai
Автор

Sir, when we pass only 1 in slice method why does it removed "Ted" and not "Tim" as i think we pass the index no. inside this method.
Sir, will u please explain this.

manishthakur
Автор

Good Evening Hitesh,


I am following up your videos from last week and need some clarifications on below mentioned:

How can we add type of operator in the below console.log using interpolation to get group of results in single query.



console.log (`

// Added number is : ${add}

// Subracted number is : ${sub}

// Multiply number is : ${mul}

// Divided number is : ${div}

// Modulus number is : ${mod}

// Greater number is : ${greater}

// Lesser number is : ${lesser}

// Equal number is : ${equal}

// `);



I have tried to use typeof as below and will getting result as string alone.



console.log (typeof`

// Added number is : ${add}

// Subracted number is : ${sub}

// Multiply number is : ${mul}

// Divided number is : ${div}

// Modulus number is : ${mod}

// Greater number is : ${greater}

// Lesser number is : ${lesser}

// Equal number is : ${equal}

// `);

kuzhalmalan
Автор

hey, Hitesh can you tell the difference between console.log(users.slice(1)); and console.log(users.splice(1)); which both do the same thing upon execution can you help from this tq in advance...

gouthamrohan
Автор

wow the inclusive and exclusive thing has been bothering me for long, what a great way to explain it, that the 2nd option is exclusive. this is definitely going to help me remember. Thanks! :)

xZecica