배열

정태수·2022년 4월 20일
0

자바스크립트

목록 보기
3/4
let testArray=[1,2,3,4,5];
let testArray2 = new Array(5); //배열선언방법

testArray[0] = 100;

for(let i = 0; i < testArray.length; i++){
    testArray[i];
}

// testArray.push(30);

// testArray.forEach(function(number, index, arr){
//     console.log("2. n:" , number, "i",  index, "a:", arr);
// })

// testArray.pop();

// testArray.forEach(function(number, index, arr){
//     console.log("3. n:" , number, "i",  index, "a:", arr);
// })

testArray.unshift(300);
testArray.forEach(function(number, index, arr){
    console.log("4. number:" , number, "index",  index, "arr:", arr);
})

testArray.shift();
testArray.forEach(function(number, index, arr){
    console.log("5. number:" , number, "index",  index, "arr:", arr);
})

let arrayMultiple = testArray.map(x => x * 2); //배열의 요소들을 x에 담아서 하ㅏ하나 다 곱해준다.
arrayMultiple.forEach(function(number, index, arr){
    console.log("6. number:" , number, "index",  index, "arr:", arr);
})

arrayMultiple.forEach(x => console.log(x));
profile
프론트엔드 개발자

0개의 댓글