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:09:24
Timcast
2 hours agoZohran Mamdani BLAMES Trump Over Bomb Threats At Polling Locations
102K50 -
3:09:52
Right Side Broadcasting Network
4 hours agoLIVE REPLAY: White House Press Secretary Karoline Leavitt Holds a Press Briefing - 11/4/25
27K8 -
1:58:04
The Charlie Kirk Show
2 hours agoGo Vote! + Healthcare and the Shutdown | Dr. Oz, Baris | 11.4.2025
29K5 -
58:49
The White House
3 hours agoPress Secretary Karoline Leavitt Briefs Members of the Media, Nov. 4, 2025
3.36K7 -
1:00:22
Sean Unpaved
2 hours agoCarousel Chaos: CFB Week 10 Shocks & Drops, Cardinals Stun MNF, & CBB's Opening Tip-Off Frenzy
6.74K1 -
1:57:43
Steven Crowder
4 hours agoFailed Hit Job: Another Trump Media Hoax Exposed
274K240 -
56:36
The Rubin Report
3 hours agoFox Hosts Stunned by Piers Morgan’s Dark Prediction for NYC Under Zohran Mamdan
25.4K39 -
LIVE
XDDX_HiTower
2 hours ago $0.61 earnedGRAY ZONE DEVLOG FOR .3.5 UPDATE!!! [RGMT CONTENT Mgr. | RGMT GL | GZW CL]
81 watching -
LIVE
LFA TV
17 hours agoLIVE & BREAKING NEWS! | TUESDAY 11/4/25
2,423 watching -
DVR
The Shannon Joy Show
3 hours agoICE Brutality In Evanston, Illinois Sparks New Outrage * GOP Seeks New FISA Re-Authorization * Are Tucker Carlson & Nick Fuentes Feds?
15.4K4