Friday, September 28, 2018

JavaScript Map Function

How does JavaScript Map Function work....

Here is an example

var numbers = [4, 9, 16, 25];

function myFunction() {
    x = document.getElementById("demo")
    x.innerHTML = numbers.map(Math.sqrt);
}

If I execute the above function as part of my Javascript it print

2,3,4,5

So what happened using map function I applied the Math.sqrt to every element of my numbers array.

1 comment:

Unknown said...

myTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance