Java Reference
In-Depth Information
it. The following code passes the
doubleAndReturn()
function to the
Array
object's
map()
method:
var numbers = [ 1, 2, 3, 4, 5 ];
function doubleAndReturn(value, index, array) {
var result = value * 2;
return result;
}
var doubledNumbers = numbers.map(doubleAndReturn);
alert("The doubled numbers are: " + doubledNumbers);
Figure 5-3 shows the results of this code. It's important to note that the
map()
method does not alter
the original array.
figure 5-3
the math object
The
Math
object provides a number of useful mathematical functions and number manipulation
methods. You take a look at some of them here, but you'll find the rest described in detail at the
Mozilla Developer Network:
https://developer.mozilla.org/en‐US/docs/Web/JavaScript/