In this example I will show you to perform square root for the given numbers using Sqrt math function in jQuery. I stored list of numbers in an array variable and loop each element in the array and perform square root from its value.$.map(). The $.map() method will takes the array and callback method as argument.
Example:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var nums = [16, 90, 256, 339];
nums= $.map(nums, function (value, index) {
return Math.sqrt(value).toFixed(2);
});
$('#divResult').html("<li >" + nums.join("</li><li>") + "</li>");
});
</script>
</head>
<body style="width: 400px;height:250px; border: 1px solid #e5dddd;color:#740c6b;">
<h2>Sqrt mathfunction in jQuery </h2>
<div id="divResult" style="color:#0094ff;" >
</div>
</body>
</html>
Output:
Post your comments / questions
Recent Article
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
- Unicode error 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
- Could not find the 'angular-devkit/build-angular:dev-server' builder's node package | Angular Error
Related Article