TypedArray의 find() 함수는 함수의 이름을 나타내는 문자열 값을 받아 배열의 요소가 제공된 함수에 의해 구현된 테스트를 통과하는지 테스트합니다. 그렇다면 테스트를 통과한 첫 번째 요소를 반환하고 else는 정의되지 않은 값을 반환합니다.
구문
구문은 다음과 같습니다.
typedArray.find(function_name)
예시
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65,21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
function testResult(element, index, array) {
var ele = element>35
return ele;
}
result = int32View.find(testResult);
document.write("Result: "+result);
</script>
</body>
</html> 출력
Contents of the typed array: 64,89,65,21,14,66,87,55 Result: 65
예시
배열에 필수 요소가 포함되어 있지 않으면 이 함수는 정의되지 않은 값을 반환합니다.
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65,21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
function testResult(element, index, array) {
var ele = element>100
return ele;
}
result = int32View.find(testResult);
document.write("Result: "+result);
</script>
</body>
</html> 출력
Contents of the typed array: 21,19,65,21,14,66,87,55 Result: undefined