JavaScript-এর Array.prototype.map() ফাংশনটি কল ফাংশনের ফলাফল সহ একটি নতুন অ্যারে তৈরি করতে ব্যবহৃত হয়।
সিনট্যাক্স নিম্নরূপ -
arr.map(function callback(currentValue[, index[, array]])
আসুন এখন JavaScript-
-এ Array.prototype.map() পদ্ধতি প্রয়োগ করিউদাহরণ
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click to display the abs() result...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
var arr = [1, -2, 3, 4, 5, -6, 7, 8, 9, 10];
var res = arr.map(Math.abs);
document.write(res);
}
</script>
</body>
</html> আউটপুট

উপরের "ফলাফল" বোতামে ক্লিক করুন -

উদাহরণ
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click to round the numbers...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
var arr = [11.4, 12.9, 25.6, 88.9];
document.getElementById("test").innerHTML = arr
function display() {
var res = arr.map(Math.round);
document.getElementById("test").innerHTML = res
}
</script>
</body>
</html> আউটপুট

সংখ্যাগুলিকে বৃত্তাকার করতে "ফলাফল" বোতামে ক্লিক করুন −
