for와 forEach의 사용법이 확실한 구분을 짓기위하여
간단하게 정리하여 구분짓기 쉽도록 하기 위함의 정리글!!
var arr = ['haha1','haha2','haha3'];
for(var i=0; i < arr.length; i ++ )
{
document.writeln(arr[i]);
}
var arr = ['haha1','haha2','haha3'];
arr.forEach(function (value, index){
document.writeln('[index] - ' + index);
document.writeln(', [value] - ' + value);
document.writeln('<br/>');
[index] - 0, [value] - haha1
[index] - 1, [value] - haha2
[index] - 2, [value] - haha3
var arr = ['haha1','haha2','haha3'];
$.each(arr, function (index, value){
document.writeln('[index] - ' + index);
document.writeln(', [value] - ' + value);
document.writeln('</br>');
});
[index] - 0, [value] - haha1
[index] - 1, [value] - haha2
[index] - 2, [value] - haha3