본문 바로가기

Front end/JS (JavaScript)

자바스크립트 (JavaScript) 배열값 가져오기 (첫번째, 마지막 배열값 불러오기)

728x90
<script>
const arr = [1, 2, 3, 4, 5];
let firstIdx = 0
let lastIdx = arr.length - 1

const firstVal = arr[firstIdx];
const lastVal = arr[lastIdx];

console.log(`firstVal : ${firstVal} \nlastVal : ${lastVal}`)
</script>

728x90