Premium Only Content

JavaScript Array Functions (#shorts)
Hi Friends,
JavaScript Array Functions
JavaScript provides many useful built-in functions for working with arrays. Here are some examples of commonly used array functions:
push(): adds one or more elements to the end of an array.
let fruits = ['apple', 'banana'];
fruits.push('orange', 'pear');
console.log(fruits); // ["apple", "banana", "orange", "pear"]
pop(): removes the last element from an array and returns it.
let fruits = ['apple', 'banana', 'orange'];
let lastFruit = fruits.pop();
console.log(lastFruit); // "orange"
console.log(fruits); // ["apple", "banana"]
shift(): removes the first element from an array and returns it.
let fruits = ['apple', 'banana', 'orange'];
let firstFruit = fruits.shift();
console.log(firstFruit); // "apple"
console.log(fruits); // ["banana", "orange"]
unshift(): adds one or more elements to the beginning of an array.
let fruits = ['apple', 'banana'];
fruits.unshift('orange', 'pear');
console.log(fruits); // ["orange", "pear", "apple", "banana"]
slice(): returns a new array containing a portion of the original array.
let fruits = ['apple', 'banana', 'orange', 'pear'];
let citrus = fruits.slice(2);
console.log(citrus); // ["orange", "pear"]
splice(): changes the contents of an array by removing or replacing existing elements and/or adding new elements.
let fruits = ['apple', 'banana', 'orange', 'pear'];
fruits.splice(1, 2, 'grape', 'melon');
console.log(fruits); // ["apple", "grape", "melon", "pear"]
concat(): merges two or more arrays and returns a new array.
let fruits = ['apple', 'banana'];
let moreFruits = ['orange', 'pear'];
let allFruits = fruits.concat(moreFruits);
console.log(allFruits); // ["apple", "banana", "orange", "pear"]
indexOf(): returns the index of the first occurrence of a specified value in an array, or -1 if it is not found.
let fruits = ['apple', 'banana', 'orange'];
let orangeIndex = fruits.indexOf('orange');
console.log(orangeIndex); // 2
filter(): returns a new array containing all elements that pass a specified test.
let numbers = [1, 2, 3, 4, 5];
let evenNumbers = numbers.filter(function(number) {
return number % 2 === 0;
});
console.log(evenNumbers); // [2, 4]
map(): returns a new array containing the results of calling a function on each element in the original array.
let numbers = [1, 2, 3, 4, 5];
let squaredNumbers = numbers.map(function(number) {
return number * number;
});
console.log(squaredNumbers); // [1, 4, 9, 16, 25]
#javascript #array #arrayfunctions #function #functions #javascriptarrayfunction #javascriptarrayfunctions #shorts #short #shortsvideo #shortsfeed #shortfeed #shortvideo #shortsyoutube #shortviral #push #pop #shift #unshift #slice #splice #concat #indexof #filter #map #princecheema_official @princecheema_official
-
1:25:23
Kim Iversen
12 hours agoFrom Doctor to Political Prisoner: Dr. Simone Gold on COVID Lies, January 6th, and Medical Tyranny
113K69 -
2:09:28
Melonie Mac
14 hours agoGo Boom Live Ep 39!
59.8K11 -
1:04:36
Man in America
15 hours ago🚨 BREAKING: Dr. Robert Young JAILED! Medical Tyrants Will Do ANYTHING to Silence Truth
86K28 -
3:01:44
I_Came_With_Fire_Podcast
13 hours agoPanama CANAL BlackROCKED | Left of PODCASTING | Ukraine AID GONE
46.9K8 -
45:56
Glenn Greenwald
13 hours agoLee Fang Reacts to Trump's Speech to Congress; Will DOGE Tackle Military Waste? | SYSTEM UPDATE #418
111K100 -
43:23
Donald Trump Jr.
13 hours agoNo Clap: Dems are a Disgrace but My Father is Bringing Back Common Sense | Triggered Ep.222
164K141 -
18:29
The Rad Factory
1 day ago $4.97 earnedBuilding Shred Eighty a Custom Honda Snow Kart
47.2K6 -
UPCOMING
Precision Rifle Network
1 day agoS4E7 Guns & Grub - What makes group size increase?
31.9K2 -
46:29
SGT Report
1 day agoAMERICA IS BACK! BYE BYE IRS!! -- Sam Anthony
80K130 -
8:56:13
Dr Disrespect
19 hours ago🔴LIVE - DR DISRESPECT - WARZONE - 150 PLAYER LOBBIES
193K20