반응형
Question.
I have an Express.js app set up using EJS templates. I successfully looped through an array with classic JS syntax:
아래 루프를 쉽게 바꿀 수 있는 방법이 있나요?
<% for (var i = 0; i < myArray.length; i++) {
this = myArray[i];
// display properties of this
} %>
But I'm wondering, is there a cleaner way to do this?
Specifically, can I use Underscore or Lodash to loop through with .each ? thank you
Answer.
You can use forEach
method.
forEach 문을 써보세요.
myArray.forEach(function(el, index) {
// el - current element, i - index
});
'프로그래밍 > 자바스크립트' 카테고리의 다른 글
Javascript - 함수의 이해 (0) | 2015.01.22 |
---|---|
Javascript - 함수 유효범위와 클로저 (0) | 2015.01.22 |
Javascript - 연산자, 제어문, 예외처리 (0) | 2015.01.21 |
Javascript - 변수, 데이터 타입, 리터럴 (0) | 2015.01.21 |
자바스크립트 - for...in 문 (0) | 2015.01.06 |
자바스크립트 - DOM level2 이벤트 모델 (0) | 2014.09.09 |
자바스크립트 - 이벤트 버블링과 버블링 막는 방법 (0) | 2014.09.07 |
자바스크립트 - 문서객체를 이용한 글자 움직이기 예제 (0) | 2014.09.06 |