0% found this document useful (0 votes)
28 views5 pages

All 30 JS Array Methods Tile Format

The document provides a comprehensive overview of 30 JavaScript array methods, detailing their functionality, example code, and output. Each method is described in Hinglish, covering operations like adding, removing, and manipulating array elements. Key methods include push, pop, shift, unshift, splice, map, filter, and others, with notes on their mutability and return values.

Uploaded by

Rohan Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views5 pages

All 30 JS Array Methods Tile Format

The document provides a comprehensive overview of 30 JavaScript array methods, detailing their functionality, example code, and output. Each method is described in Hinglish, covering operations like adding, removing, and manipulating array elements. Key methods include push, pop, shift, unshift, splice, map, filter, and others, with notes on their mutability and return values.

Uploaded by

Rohan Sonawane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

All 30 JavaScript Array Methods (Hinglish Tile Format)

push()
Kaam: End me item add karta hai
Code: let a = [1,2]; a.push(3);
Output: [1,2,3]
Note: Original array change hota hai (mutable)

pop()
Kaam: Last item remove karta hai
Code: let a = [1,2,3]; a.pop();
Output: [1,2]
Note: Return karega '3' (jo remove hua)

shift()
Kaam: First element remove karta hai
Code: let a = [10, 20, 30]; a.shift();
Output: [20, 30]
Note: Return karega 10 (jo remove hua)

unshift()
Kaam: Start me item add karta hai
Code: let a = [2,3]; a.unshift(1);
Output: [1,2,3]
Note: Return karta hai new length (3)

splice()
Kaam: Item add/remove dono kar sakta hai
Code: let a = [1,2,3,4]; a.splice(1, 2, 9, 8);
Output: [1,9,8,4]
Note: 1 index se 2 item remove karke 9 aur 8 daal diye

reverse()
Kaam: Array ke order ko ulta karta hai
Code: let a = [1,2,3]; a.reverse();
Output: [3,2,1]
Note: Original array mutate hota hai

sort()
Kaam: Array ko ascending order me sort karta hai (string by default)
Code: let a = [3,1,2]; a.sort();
Output: [1,2,3]
Note: Default string compare karta hai, numbers ke liye callback dena hota hai

join()
Kaam: Array elements ko string me jodta hai
Code: let a = ["a", "b", "c"]; a.join("-");
Output: "a-b-c"
Note: Separator specify kar sakte ho

fill()
Kaam: Array ke sabhi ya kuch elements ko ek hi value se fill karta hai
Code: let a = [1,2,3]; a.fill(0);
Output: [0,0,0]
Note: Original array change hota hai

copyWithin()
Kaam: Array ke ek part ko dusre part me copy karta hai
Code: let a = [1,2,3,4]; a.copyWithin(1, 2);
Output: [1,3,4,4]
Note: Original array mutate hota hai

map()
Kaam: Har element par function apply karke naya array banata hai
Code: let a = [1,2,3]; let b = a.map(x => x*2);
Output: [2,4,6]
Note: Original array nahi badalta
filter()
Kaam: Condition ke basis par selected items ka naya array banata hai
Code: let a = [1,2,3,4]; let b = a.filter(x => x%2 === 0);
Output: [2,4]
Note: Original array safe rehta hai

reduce()
Kaam: Saare elements ko combine karke single value banata hai
Code: let a = [1,2,3]; let sum = a.reduce((acc, x) => acc + x, 0);
Output: 6
Note: Accumulator pattern follow karta hai

forEach()
Kaam: Har element par ek function run karta hai (return nahi karta)
Code: let a = [1,2,3]; a.forEach(x => console.log(x));
Output: 1 2 3
Note: Kuch return nahi karta, sirf loop ke liye

every()
Kaam: Check karta hai ki kya har element condition ko pass karta hai
Code: [2,4,6].every(x => x%2 === 0);
Output: true
Note: Agar ek bhi fail hua to false

some()
Kaam: Check karta hai ki kya koi ek element condition pass karta hai
Code: [1,3,4].some(x => x%2 === 0);
Output: true
Note: Ek match mila to true

find()
Kaam: Pehla element return karta hai jo condition match kare
Code: [1,3,4,6].find(x => x > 3);
Output: 4
Note: Sirf pehla match return karta hai

findIndex()
Kaam: Pehle match ka index return karta hai
Code: [1,3,4,6].findIndex(x => x > 3);
Output: 2
Note: Match nahi mila to -1 return karta hai

flat()
Kaam: Nested arrays ko flat (simple) bana deta hai
Code: [1, [2, 3], [4]].flat();
Output: [1,2,3,4]
Note: 1 level deep flatten karta hai by default

flatMap()
Kaam: Map ke baad flatten karta hai
Code: [1,2,3].flatMap(x => [x, x*2]);
Output: [1,2,2,4,3,6]
Note: Map + flat ka combo

toReversed()
Kaam: Reverse karta hai but original array ko nahi chhedta
Code: let a = [1,2,3]; let b = a.toReversed();
Output: [3,2,1]
Note: Original array safe

toSorted()
Kaam: Sort karta hai bina original ko badle
Code: let a = [3,1,2]; let b = a.toSorted();
Output: [1,2,3]
Note: Original array mutate nahi hota

toSpliced()
Kaam: Splice jaisa kaam karta hai but original array ko safe rakhta hai
Code: let a = [1,2,3,4]; let b = a.toSpliced(1, 2, 9);
Output: [1,9,4]
Note: Immutable version of splice

at()
Kaam: Index se value deta hai (negative index bhi support karta hai)
Code: let a = [10, 20, 30]; a.at(-1);
Output: 30
Note: a[-1] ki tarah kaam karta hai

Array.isArray()
Kaam: Check karta hai value array hai ya nahi
Code: Array.isArray([1,2,3]);
Output: true
Note: true ya false deta hai

Array.from()
Kaam: Array-like ya iterable object ko real array me badalta hai
Code: Array.from('abc');
Output: ['a','b','c']
Note: Useful in converting strings or NodeLists

Array.of()
Kaam: Arguments ko ek naya array bana deta hai
Code: Array.of(1,2,3);
Output: [1,2,3]
Note: Array banane ka ek aur tareeka

You might also like