Array.map()
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript Array.map()</h1>
- <p>通过对每个数组元素执行函数来创建新数组。</p>
- <p id="demo"></p>
- <script>
- var numbers1 = [45, 4, 9, 16, 25];
- var numbers2 = numbers1.map(myFunction);
- document.getElementById("demo").innerHTML = numbers2;
- function myFunction(value, index, array) {
- return value * 2;
- }
- </script>
- </body>
- </html>