forEach문 질문입니다.

forEach문 질문입니다.

QA

forEach문 질문입니다.

본문


files = 
{ attachFile1: 
   File {
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 87911,
     path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
     name: 'KakaoTalk_20171024_200451916.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2017-10-30T07:09:47.527Z,
     _writeStream: 
      WriteStream {
        _writableState: [Object],
        writable: false,
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 87911,
        closed: true } },
  attachFile2: 
   File {
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 8588,
     path: 'client\\assets\\upload\\qna\\file\\upload_16c11c425a7190f49c0f72fb30c57e82.jpg',
     name: '7.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: 2017-10-30T07:09:47.528Z,
     _writeStream: 
      WriteStream {
        _writableState: [Object],
        writable: false,
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'client\\assets\\upload\\qna\\file\\upload_16c11c425a7190f49c0f72fb30c57e82.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 8588,
        closed: true } } }

 

files 안에는 {

attachFile1 : File{key:value, key:value }

attachFile2 : File{key:value, key:value }

.

.

.

attachFile + N : File{key:value, key:value }

}

 

이런식으로 값이 담겨있는데

 

여기에서 

files.forEach()

하면 type에러가 발생하네요..

 

위 데이터를 저는 아래처럼 하고 싶습니다. 


[{   path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
     name: 'KakaoTalk_20171024_200451916.jpg',
     type: 'image/jpeg'},
{
path: 'client\\assets\\upload\\qna\\file\\upload_16c11c425a7190f49c0f72fb30c57e82.jpg',
     name: '7.jpg',
     type: 'image/jpeg'
}
.
.
.
 
]

 

도와주세요 ㅠㅠ

#js

이 질문에 댓글 쓰기 :

답변 2

수정!  사용 사능하시길 바랍니다. 


<script>
var files =  [{attachFile1:{File :{
    name: "sss",
    file: {
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 87911,
     path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
     name: 'KakaoTalk_20171024_200451916.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: '2017-10-30T07:09:47.527Z',
      WriteStream :{
        _writableState: [Object],
        writable: false,
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 87911,
    closed: true }}}
},
attachFile2:{File :{
    name: "sss",
    file: {
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     size: 87911,
     path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
     name: 'KakaoTalk_20171024_200451916.jpg',
     type: 'image/jpeg',
     hash: null,
     lastModifiedDate: '2017-10-30T07:09:47.527Z',
      WriteStream :{
        _writableState: [Object],
        writable: false,
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
        fd: null,
        flags: 'w',
        mode: 438,
        start: undefined,
        autoClose: true,
        pos: undefined,
        bytesWritten: 87911,
    closed: true }}}
}
}]
 
var newArr = []; 
var newFile = [];
files.forEach(function(att, i) {
   newArr = att;
});
for(i = 1 ;i <10 ; i ++){
    
    var attName = 'attachFile'+i.toString(); 
    if(typeof newArr[attName] !== 'undefined'){
        newFile[i-1] = {name :  newArr[attName]['File'].file.name ,path: newArr[attName]['File'].file.path, type: newArr[attName]['File'].file.type}
         
    }else{
        break;
    }
}

console.log(newFile);
 
</script>
 

 

files =   <-- 함수 JSON 텍스트 보고싶네요.

답변을 작성하시기 전에 로그인 해주세요.
전체 312
QA 내용 검색
filter #js ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT