push(), pop(), shift(), unshift(), slice(), splice() in JavaScript - #25

Publicado em: 04 Abril 2024
no canal de: Everyday Be Coding
325
6

#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


Nesta página do site você pode assistir ao vídeo on-line push(), pop(), shift(), unshift(), slice(), splice() in JavaScript - #25 duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário Everyday Be Coding 04 Abril 2024, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 325 vezes e gostou 6 espectadores. Boa visualização!