#JavaScript
#Programming
#WebDevelopment
#Arrays
#ArrayMethods
#PushMethod
#PopMethod
#ShiftMethod
#UnshiftMethod
#SliceMethod
#SpliceMethod
#Coding
#Developer
#Tech
#Tutorial
#LearnJavaScript
#Frontend
#SoftwareDevelopment
#CodeNewbie
#developercommunity
JavaScript full playlist : • What is JavaScript? - #1 #JavaScript #JS #...
These are some of the most commonly used array manipulation methods in JavaScript:
push(): Adds one or more elements to the end of an array and returns the new length of the array.
JavaScript code:
const arr = [1, 2, 3];
arr.push(4);
console.log(arr); // [1, 2, 3, 4]
pop(): Removes the last element from an array and returns that element.
JavaScript code:
const arr = [1, 2, 3];
const poppedElement = arr.pop();
console.log(poppedElement); // 3
console.log(arr); // [1, 2]
shift(): Removes the first element from an array and returns that element. This operation changes the length of the array.
JavaScript code
const arr = [1, 2, 3];
const shiftedElement = arr.shift();
console.log(shiftedElement); // 1
console.log(arr); // [2, 3]
unshift(): Adds one or more elements to the beginning of an array and returns the new length of the array.
JavaScript code:
const arr = [2, 3];
arr.unshift(1);
console.log(arr); // [1, 2, 3]
slice(): Returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included). The original array will not be modified.
JavaScript code:
const arr = [1, 2, 3, 4, 5];
const slicedArr = arr.slice(1, 4);
console.log(slicedArr); // [2, 3, 4]
console.log(arr); // [1, 2, 3, 4, 5]
splice(): Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
JavaScript code:
const arr = [1, 2, 3, 4, 5];
arr.splice(2, 1); // Removes 1 element starting from index 2
console.log(arr); // [1, 2, 4, 5]
arr.splice(2, 0, 'a', 'b'); // Inserts 'a' and 'b' at index 2
console.log(arr); // [1, 2, 'a', 'b', 4, 5]
These array methods are fundamental for manipulating arrays in JavaScript and are widely used in various applications.
Chapter :
00:00 intro
00:14 Push()
00:35 Pop()
00:53 Shift()
01:11 unshift()
01:30 slice()
02:05 splice()
02:41 Summery
Thank you for watching this video
EVERYDAY BE CODING
On this page of the site you can watch the video online push(), pop(), shift(), unshift(), slice(), splice() in JavaScript - #25 with a duration of hours minute second in good quality, which was uploaded by the user Everyday Be Coding 04 April 2024, share the link with friends and acquaintances, this video has already been watched 325 times on youtube and it was liked by 6 viewers. Enjoy your viewing!