JavaScript 中的 TypedArray.map() 函数
TypedArray 对象的 map() 函数接受一个函数名称,并对类型化数组中的每个元素调用该函数,然后返回结果。
语法
其语法如下
typedArray.map()
示例
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([11, 5, 13, 4, 15, 3, 17, 2, 19, 8 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
function square(ele) {
return ele*ele;
}
var result = int32View.map(square);
document.write("Specified element occurred at the index: "+result);
</script>
</body>
</html>输出
Contents of the typed array: 11,5,13,4,15,3,17,2,19,8 Specified element occurred at the index: 121,25,169,16,225,9,289,4,361,64
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP