자바스크립트 배열에 push()로 넣는것과 = 로 넣는것 차이 있나요?
가람슬기
2023.04.01
document.getElementById(id) 라는 요소를 배열에 담으려고 하는데요.
var targets = new Array();
targets[0] = document.getElementById(id0);
targets[1] = document.getElementById(id1);
targets[2] = document.getElementById(id2);
targets[3] = document.getElementById(id3);
이렇게 담는 것과
targets.push( document.getElementById(id0) );
targets.push( document.getElementById(id1) );
targets.push( document.getElementById(id2) );
targets.push( document.getElementById(id3) );
이렇게 담는 것이 이상하게 약간 차이를 발견했거든요;
참고로 저 아이디를 가진 태그요소는 모두 A 태그입니다.
이퀄로 담으면 href 값이 넘어가는 것 같더라구요.
혹시 이퀄(=)과 푸쉬(push) 차이가 있나요?