Skip to content
JavaScript

3. JavaScript Array Methods in Hindi – map, filter, reduce, sort aur slice

November 23, 2026 6 min read

नमस्ते दोस्तों! 👋

Swagat hai The Easy Master par!

Products ki list, students ke marks, orders, notifications – asli apps mein data lagbhag hamesha list mein aata hai. Aur interview mein sabse zyada jo code likhwaya jaata hai, woh bhi lists par hota hai: "pass students nikalo", "total karo", "top 3 dikhao".

Is JavaScript array methods in Hindi post mein:

✅ Loop – aur <= wali chhoti si galti jo NaN bana deti hai
✅ map – har item badlo
✅ filter – kuch items rakho
✅ reduce – sabko jod kar ek value
✅ find, some, every
✅ sort – numbers ke saath sabse bada trap
✅ slice vs splice aur original array ko badalne se bachana

Strings wale post ki tarah yahan bhi har output asli mein chala kar likha hai.

1. Array ki Basics

Code
const fruits = ['aam', 'kela', 'seb'];
console.log(fruits.length, fruits[0], fruits.at(-1));
fruits.push('angoor');
console.log(fruits);
console.log(fruits.includes('kela'), fruits.indexOf('seb'));

Output:

Code
3 aam seb
[ 'aam', 'kela', 'seb', 'angoor' ]
true 2

2. Loop – aur Ek Chhoti si Galti

Array ka index 0 se shuru hota hai, isliye aakhri index length - 1 hai:

Code
const sales = [120, 80, 200];
let sum = 0;
for (let i = 0; i <= sales.length; i++) {
  sum += sales[i];
}
console.log(sum);
console.log(sales[3]);

Output:

Code
NaN
undefined

<= ki wajah se loop ek baar zyada chala, sales[3] undefined tha, aur number + undefined = NaN. Ye off-by-one bug hai – AI ke likhe code mein bhi khoob milta hai. Sahi: i < sales.length. Aur jab index chahiye hi nahi, to for...of sabse saaf hai:

Code
let total = 0;
for (const amount of sales) {
  total += amount;
}
console.log(total);

Output:

Code
400

3. map – Har Item Badlo

map har item par ek function chalata hai aur utne hi items ki nayi array deta hai:

Code
const prices = [100, 250, 499];
const withGst = prices.map((p) => Math.round(p * 1.18));
console.log(withGst);
console.log(prices);

Output:

Code
[ 118, 295, 589 ]
[ 100, 250, 499 ]

Original prices waisi hi rahi – map nayi array banata hai. (Math.round isliye ki 499 * 1.18 seedha 588.8199999999999 deta hai – numbers wale post ki 0.1 + 0.2 wali baat.)

Objects ki list se ek hi cheez nikalni ho:

Code
const products = [
  { name: 'Pen', price: 10, stock: 40 },
  { name: 'Notebook', price: 60, stock: 0 },
  { name: 'Bag', price: 799, stock: 5 },
];
console.log(products.map((p) => p.name));

Output:

Code
[ 'Pen', 'Notebook', 'Bag' ]

Sabse Aam Galti

Code
console.log(products.map((p) => p.stock > 0));

Output:

Code
[ true, false, true ]

Maangna tha "jo stock mein hain unke naam", aur mila true/false ka array. map ginti nahi badalta – har item ka ek jawab deta hai. Items hatane ke liye filter chahiye.

4. filter – Kuch Items Rakho

Code
const inStock = products.filter((p) => p.stock > 0);
console.log(inStock.map((p) => p.name));

Output:

Code
[ 'Pen', 'Bag' ]

filter sirf woh items rakhta hai jinke liye function true lautaye. Aur dekhiye – filter ke baad map lagaya. Ise chaining kehte hain: pehle chhanto, phir badlo.

Code
const cheapNames = products
  .filter((p) => p.price < 100)
  .map((p) => p.name.toUpperCase());
console.log(cheapNames);

Output:

Code
[ 'PEN', 'NOTEBOOK' ]

5. reduce – Sabko Jod kar Ek Value

Code
const cart = [{ item: 'Pen', qty: 3, price: 10 }, { item: 'Bag', qty: 1, price: 799 }];
const bill = cart.reduce((sum, row) => sum + row.qty * row.price, 0);
console.log(bill);

Output:

Code
829

reduce(fn, shuruwaat) – har item par sum aage badhta hai. Aakhri 0 shuru ki value hai. Ise chhodiye mat – khaali array par bina shuruwaat ke reduce error deta hai:

Code
[].reduce((a, b) => a + b);

Output:

Code
TypeError: Reduce of empty array with no initial value

reduce se ginti bhi kar sakte hain – jaise har city se kitne students:

Code
const cities = ['Jaipur', 'Pune', 'Jaipur', 'Delhi', 'Pune', 'Jaipur'];
const count = cities.reduce((acc, c) => {
  acc[c] = (acc[c] || 0) + 1;
  return acc;
}, {});
console.log(count);

Output:

Code
{ Jaipur: 3, Pune: 2, Delhi: 1 }

Average aur Khaali List

Code
function averageMarks(list) {
  return list.reduce((a, b) => a + b, 0) / list.length;
}
console.log(averageMarks([60, 70, 80]));
console.log(averageMarks([]));

Output:

Code
70
NaN

Khaali list par 0 / 0 = NaN. Bhaag se pehle length check kijiye – numbers wale post ki wahi baat.

6. find, some, every

Code
const marks = [{ n: 'Asha', m: 72 }, { n: 'Ravi', m: 28 }, { n: 'Neha', m: 91 }];
console.log(marks.find((s) => s.m > 90));
console.log(marks.some((s) => s.m < 33));
console.log(marks.every((s) => s.m < 33));
console.log(marks.find((s) => s.m > 100));

Output:

Code
{ n: 'Neha', m: 91 }
true
false
undefined
  • find – pehla item jo shart maane (na mile to undefined)
  • some – kya koi ek maanta hai?
  • every – kya sab maante hain?

7. sort – Numbers ka Sabse Bada Trap

Code
const scores = [9, 100, 25, 70];
console.log([...scores].sort());

Output:

Code
[ 100, 25, 70, 9 ]

[100, 25, 70, 9]? Bina kuch bataye sort() sabko string bana kar dictionary ki tarah lagata hai – "100" ka pehla character "1" hai, jo "2" se pehle aata hai. Numbers ke liye compare function dijiye:

Code
console.log([...scores].sort((a, b) => a - b));
console.log([...scores].sort((a, b) => b - a));

Output:

Code
[ 9, 25, 70, 100 ]
[ 100, 70, 25, 9 ]

a - b chhote se bada, b - a bade se chhota. Objects ke liye: products.sort((x, y) => x.price - y.price).

sort Original Array Badal Deta Hai

Code
const original = [3, 1, 2];
const sorted = original.sort((a, b) => a - b);
console.log(sorted, original);

Output:

Code
[ 1, 2, 3 ] [ 1, 2, 3 ]

original bhi badal gaya! Isliye upar har jagah [...scores] likha tha – pehle copy, phir sort. Naye JavaScript mein toSorted() bhi hai jo copy hi lautata hai:

Code
const list = [3, 1, 2];
console.log(list.toSorted((a, b) => a - b), list);

Output:

Code
[ 1, 2, 3 ] [ 3, 1, 2 ]

8. slice vs splice

Naam milte-julte hain, kaam bilkul alag:

Code
const nums = [10, 20, 30, 40, 50];
console.log(nums.slice(1, 3));
console.log(nums);
const removed = nums.splice(1, 2);
console.log(removed, nums);

Output:

Code
[ 20, 30 ]
[ 10, 20, 30, 40, 50 ]
[ 20, 30 ] [ 10, 40, 50 ]
Baatslice(start, end)splice(start, kitne)
Original badalta hai?NahiHaan
Doosra argumentend index (shaamil nahi)kitne hatane hain
Lautata haiCopy ka hissaHataye gaye items

slice(1, 3) ka matlab "index 1 se 3 tak, 3 chhod kar" – lambai nahi. List ko tukdon mein todte waqt slice(i, i + size) likhna padta hai, slice(i, size) nahi.

9. Common Mistakes

GaltiKya hota haiSahi tareeka
i <= arr.lengthaakhir mein undefined, sum NaNi < arr.length ya for...of
items hatane ke liye maptrue/false ka arrayfilter
nums.sort() numbers par[100, 25, 9]sort((a, b) => a - b)
arr.sort(...) original parcaller ki array badal gayi[...arr].sort() ya toSorted()
reduce bina shuruwaatkhaali array par errorreduce(fn, 0)
slice(i, size)doosra tukda khaalislice(i, i + size)

10. Interview Mein Kya Poochte Hain

  • map, filter, reduce mein farq? – badlo / chhanto / jodo. Ek line mein bolna seekhiye.
  • [10, 9, 100].sort() ka output? – [10, 100, 9], aur kyun.
  • slice vs splice? – kaunsa original badalta hai.
  • Array ki copy kaise? – [...arr], arr.slice(); aur nested objects ke liye shallow vs deep copy.

Async code mein arrays (Promise.all, forEach ke andar await) ke liye dekhiye Async Await vs Promises.

Ab Khud Karke Dekho 💪

Neeche ke challenges mein yahi methods lagenge – pass students ke naam, class ka average, IPL top scorers, list ke tukde. Kuch mein code AI ne likha hai aur aapko uski galti pakadni hai – aaj ke interview mein ye skill khaas dekhi jaati hai. Saare challenges: quiz.theeasymaster.com/challenges.

Author at The Easy Master.

Related posts

JavaScript Cheat Sheet: Syntax, Examples & JS Concepts in Hindi

The tutorial teaches it; the cheat sheet is for when you just need reminding.

Leave a Reply

Your email address will not be published. Required fields are marked *