[Go to site: main page, start]

0% found this document useful (0 votes)
5 views6 pages

Js Array Methods

The document provides an overview of various array methods in JavaScript, including push, pop, splice, slice, map, filter, reduce, find, includes, and sort. Each method is explained with an introduction, arguments, example code, and output. The document serves as a quick reference for understanding how to manipulate arrays using these methods.

Uploaded by

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

Js Array Methods

The document provides an overview of various array methods in JavaScript, including push, pop, splice, slice, map, filter, reduce, find, includes, and sort. Each method is explained with an introduction, arguments, example code, and output. The document serves as a quick reference for understanding how to manipulate arrays using these methods.

Uploaded by

Gee Lucknow
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

🧱 🔥 Boilerplate (Console version)

<!DOCTYPE html>
<html>
<head>
<title>Array Methods Console</title>
</head>
<body>

<h2>Open Console (Right Click → Inspect → Console)</h2>

<script>
// Yaha se code start hoga
</script>

</body>
</html>

✅ 1. push()
👉 Intro: Array ke end me value add karta hai

👉 Arguments:
push(value1, value2, ...)

 Ek ya multiple values add kar sakte ho


 Sab values end me add hoti hain

<script>
let arr = [1,2];
[Link](3,4);

[Link]("push:", arr);
</script>

👉 Output (Console):

push: [1,2,3,4]

👉 Explanation:
3 aur 4 last me add ho gaye
✅ 2. pop()
👉 Intro: Last element remove karta hai

👉 Arguments: ❌ koi nahi

<script>
let arr = [1,2,3];
let removed = [Link]();

[Link]("pop array:", arr);


[Link]("removed value:", removed);
</script>

👉 Output:

pop array: [1,2]


removed value: 3

👉 Explanation:
Last value remove ho gayi aur return bhi hui

✅ 3. splice()
👉 Intro: Add + remove + replace sab karta hai

👉 Arguments:
splice(startIndex, deleteCount, item1, item2...)

<script>
let arr = [1,2,3,4];
[Link](1,2,99,100);

[Link]("splice:", arr);
</script>

👉 Output:

splice: [1,99,100,4]

👉 Explanation:
Index 1 se 2 elements (2,3) remove → 99,100 add
✅ 4. slice()
👉 Intro: Copy array banata hai

👉 Arguments:
slice(start, end)

<script>
let arr = [10,20,30,40];
let res = [Link](1,3);

[Link]("slice:", res);
</script>

👉 Output:

slice: [20,30]

👉 Explanation:
Index 1 se 3 (end exclude)

✅ 5. map()
👉 Intro: Har element ko modify karta hai

👉 Arguments:
map(function(element, index, array))

<script>
let arr = [1,2,3];
let res = [Link]((x,i)=> x+i);

[Link]("map:", res);
</script>

👉 Output:

map: [1,3,5]

👉 Explanation:
1+0, 2+1, 3+2
✅ 6. filter()
👉 Intro: Condition ke hisab se select karta hai

👉 Arguments:
filter(function(element))

<script>
let arr = [1,2,3,4];
let res = [Link](x => x>2);

[Link]("filter:", res);
</script>

👉 Output:

filter: [3,4]

✅ 7. reduce()
👉 Intro: Sab values ko combine karta hai

👉 Arguments:
reduce(function(accumulator, current), initialValue)

<script>
let arr = [1,2,3];
let sum = [Link]((a,b)=>a+b,0);

[Link]("reduce:", sum);
</script>

👉 Output:

reduce: 6

👉 Step:
0+1 → 1+2 → 3+3 = 6

✅ 8. find()
👉 Intro: Pehla matching element deta hai
👉 Arguments:
find(function(element))

<script>
let arr = [5,10,15];
let res = [Link](x => x>8);

[Link]("find:", res);
</script>

👉 Output:

find: 10

✅ 9. includes()
👉 Intro: Check karta hai value exist hai ya nahi

👉 Arguments:
includes(value, startIndex optional)

<script>
let arr = [1,2,3];
[Link]("includes:", [Link](2));
</script>

👉 Output:

includes: true

✅ 10. sort()
👉 Intro: Array sort karta hai

👉 Arguments:
sort(compareFunction)

<script>
let arr = [10,2,5];
[Link]((a,b)=>a-b);

[Link]("sort:", arr);
</script>

👉 Output:
sort: [2,5,10]

You might also like