If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
JavaScript Array map() function का use एक callback function के through Array के हर एक element को visit करने के लिए किया जाता है।
map() function Array के प्रत्येक value को user defined callback function में send करता है , और एक Array नई values के साथ return करता है।
Callback Functions वो function होते हैं जो किसी दूसरे function में as an arguments pass किये जाते हैं। और जिस function में ये pass किये जाते हैं उन्हें Higher - Order Function कहते हैं।
JavaScript Callback Functions
array.map(function(currentValue, index, array), value);
function(currentValue, index, array) | required : यह callback function Array के हर एक element के लिए run होता है। इसमें तीन Parameters pass किये जाते हैं।
value | optional : यह value callback function में pass करने के लिए होती है , जिसे function में this variable के through access कर सकते हैं , अगर value pass नहीं करते हैं तो by default "undefined" जाता है।
Return Value : यह एक new Array return करता है , जिसका हर एक element को callback function द्वारा generate किया जाता है।
File : js_array_map.html
<!DOCTYPE html>
<html>
<body>
<script>
function myfun(value , index, arr)
{
return value*5;
}
var arr=[2, 5, 6, 8, 8];
let new_arr = arr.map(myfun, 'my value');
document.writeln(new_arr);
</script>
</body>
</html>
10,25,30,40,40
Hi ! My name is Rahul Kumar Rajput. I'm a back end web developer and founder of learnhindituts.com. I live in Uttar Pradesh (UP), India and I love to talk about programming as well as writing technical tutorials and tips that can help to others.
Get connected with me. :) LinkedIn Twitter Instagram Facebook