채택완료

이것 반복문드로 만들수 있을까요?

2017-10-20 (금) 17:00:12 3,107
Copy
const uploadFiles = []  // note:  upload File Info        if (file1) { uploadFiles.push(file1) }        if (file2) { uploadFiles.push(file2) }        if (file3) { uploadFiles.push(file3) }        if (file4) { uploadFiles.push(file4) }        if (file5) { uploadFiles.push(file5) }

숫자가 1,2,3,4,5 이런식으로 증가하는데 

소스를 줄일수 있는 방법이 있을까 하고 질문드립니다.

|

답변 1개 / 댓글 3개

채택된 답변
+20 포인트
2017-10-20 (금) 17:17:10
Copy
for (var i =1 ; i <= 5; i++) {    if (file.concat(i)) { uploadFiles.push(file.concat(i)) }}

이렇게 하면 되려나요?..

답변에 대한 댓글 3개

올~

eval 로 계속 구현하였었는데 저런것도 있었네요.
감사합니다.
감사합니다.

답변을 작성하려면 로그인이 필요합니다.