Javascript Array Iteration in Hindi – Array Iteration in Javascript in Hindi

 इस Javascript Tutorial में Javascript Array Iteration in HindiArray Iteration in Javascript in Hindi के बारे में पढ़ेंगे।



Javascript Array Iteration in Hindi

Array Iteration का Use Array के प्रत्येक Element पे कुछ Operation Perform करने के लिए किया जाता है। Array Iteration Methods की पूरी List नीचे दी गयी है। जिनके बारे में अच्छे से समझाया भी गया है। आप इनको पूरी तरह ध्यान से पढ़े। क्युकी इनका Use Array Element पे Operation Perform करने के लिए किया जाता है।

forEarch() Method

forEach() Method के द्वारा प्रत्येक Array Element पे एक बार में Function Execute कर सकते है। इसके द्वारा प्रत्येक Element पे Function Call कर सकते है। इस Function में तीन Argument होते है।

  1. The item Value
  2. The item Index
  3. The array itself



<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
const numbers = [45, 4, 9, 16, 25];
let txt = "";
numbers.forEach(myFunction);
document.getElementById("demo").innerHTML = txt;
function myFunction(value, index, array) {
txt += value + "<br>";
}
</script>
</body>
</html>

Output

45
4
9
16
25

map() Method

map() Method Array के सभी Element पे Perform करके एक New Array Create करता है। ये बिना Value के Array Element पे Perform नहीं करता है। ये Original Array में कोई भी Changing नहीं करता है। इसमें तीन Argument होते है।

  1. The Item Value
  2. The Item Index
  3. The Array Itself

<!DOCTYPE html>
<html>
<body>
<p id="map1"></p>
<script>
const numbers1 = [12, 8, 6, 16, 22];
const numbers2 = numbers1.map(myFunction);
document.getElementById("map1").innerHTML = numbers2;
function myFunction(value, index, array) {
return value * 5;
}
</script>
</body>
</html>

Output

60,40,30,80,110

Reduce() Method

Reduce() method सभी Array Element पे एक Function Run करता है, और उन सभी को Single Value में show करा देता है। जैसे एक Example नीचे दे रहा हूँ। जो की सभी Array Element को Add के देता है। और Single Value में Result Show कराता है।

<!DOCTYPE html>
<html>
<body>
<p id="demo1"></p>
<script>
const numbers = [39, 2, 8, 15, 24];
let sum = numbers.reduce(myFunction);
document.getElementById("demo1").innerHTML = "The sum is " + sum;
function myFunction(total, value, index, array) {
return total + value;
}
</script>
</body>
</html>

Output 

The sum is 88

इसमें Total 4 Argument होते है।

  1. The Total Value (The Initial Value)
  2. The Item Value
  3. The Item Index
  4. The Array Itself

Filter() Method

इस Method के द्वारा Array में एक condition लगा सकते है। फिर Condition का जो भी Result है। वो हमें एक New Array के रूप में देता है।


<!DOCTYPE html>
<html>
<body>
<p id="vss"></p>
<script>
const numbers = [41, 4, 9, 13, 19];
const over18 = numbers.filter(myFunction);
document.getElementById("vss").innerHTML = over18;
function myFunction(value, index, array) {
return value > 18;
}
</script>
</body>
</html>

Output

41,19

every() Method

ये method check करता है की जो Condition लगायी है। सभी Array Values उसको Pass कर रही है या नहीं।

<!DOCTYPE html> 
<html>
<body>
<p id="vss"></p>
<script> const numbers = [41, 4, 9, 13, 19];
const over18 = numbers.every(myFunction);
document.getElementById("vss").innerHTML = over18;
function myFunction(value, index, array) {
return value > 18; }
</script>
</body>
</html>

Output 

false

यहाँ पे Condition Check हो रही है, की सभी Value 18 से बड़ी है। सभी Value 18 से बड़ी नहीं है, इसलिए false output दे रहा है।

Comments

Popular posts from this blog

Mazda Pickups Playing It Up In The Us Market

Types of Computer Based on Size in Hindi (आकर के आधार पर Computer के प्रकार )

Finding A College Scholarship For A Single Mother