JavaScript arrayBuffer.slice() 메서드는 내용이 시작부터 끝까지 포함된 다른 arrayBuffer의 복사본인 새 arrayBuffer를 반환합니다.
다음은 arrayBuffer.slice() 메서드에 대한 코드입니다. -
예시
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .sample, .result { font-size: 18px; font-weight: 500; color: red; } .result { color: black; } </style> </head> <body> <h1>JavaScript arrayBuffer.slice() property</h1> <div class="sample">Original array buffer:</div> <div class="result">Sliced array buffer:</div> <button class="Btn">CLICK HERE</button> <h3> Click on the above button to slice the array buffer to make its copy </h3> <script> let resultEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); const buffer = new ArrayBuffer(16); const int32View = new Int32Array(buffer); int32View[0] = 11; int32View[1] = 22; int32View[2] = 33; int32View.forEach((item) => { sampleEle.innerHTML += item + " , "; }); const slicedBuffer = new Int32Array(buffer.slice(0, 8)); document.querySelector(".Btn").addEventListener("click", () => { slicedBuffer.forEach((item) => { resultEle.innerHTML += item + " , "; }); }); </script> </body> </html>
출력
'여기를 클릭' 버튼을 클릭하면 -