JavaScript의 Array.of() 메서드는 변수를 매개변수 값으로 사용하여 새 배열 인스턴스를 생성하는 데 사용됩니다.
구문은 다음과 같습니다 -
Array.of(elements....)
위의 요소는 매개변수 값입니다.
이제 JavaScript에서 Array.of() 메서드를 구현해 보겠습니다.
예시
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Click the button to display the values in Console</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
console.log(Array.of(10, 20, 30, 40 ,50));
}
</script>
</body>
</html> 출력

"결과"를 클릭하고 콘솔에서 출력을 확인하십시오 -

예시
<!DOCTYPE html>
<html>
<body>
<h2>Demo Heading</h2>
<p>Get the student names with top 5 ranks...</p>
<button onclick="display()">Result</button>
<p id="test"></p>
<script>
function display() {
console.log(Array.of("Kevin", "Tom", "Ryan", "Jacob", "Jack"));
}
</script>
</body>
</html> 출력

"결과" 버튼을 클릭하고 콘솔에서 결과를 확인하십시오 -
