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:50:43
Tucker Carlson
28 minutes agoChris Williamson’s Advice to Men: How to Survive a World of OnlyFans and AI Girlfriends
4 -
1:07:25
Timcast
1 hour agoBomb DETONATED At Harvard, Attacks On Ice Agents SKYROCKET
47K64 -
1:55:31
Steven Crowder
4 hours agoTucker Carlson & MAGA: Everyone is Missing the Point
235K215 -
1:11:22
The Rubin Report
2 hours agoWatch Joe Rogan’s Face as Elon Musk Exposes How Dems Are Cheating in Plain Sight
23.4K45 -
1:01:07
VINCE
4 hours agoThe Walls Are Closing In On The Deep State | Episode 160 - 11/03/25
183K135 -
LIVE
LFA TV
19 hours agoLIVE & BREAKING NEWS! | MONDAY 11/3/25
2,864 watching -
1:31:18
Graham Allen
5 hours agoErika Fights Back: Vows To EXPOSE TRUTH & DEMANDS Trial Goes Public!! Left Says Her Grief Is FAKE!
130K81 -
2:08:47
Badlands Media
9 hours agoBadlands Daily: November 3, 2025 – Tariff Wars, SNAP Panic & Brennan Gets Confronted
53.9K15 -
2:59:32
Wendy Bell Radio
8 hours agoThings Will Get Worse Before They Get Better
78K106 -
1:18:28
The Big Migâ„¢
5 hours agoICE Will Use Private Bounty Hunters, LFG
20.1K13