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'
}
.
.
.
]
도와주세요 ㅠㅠ
!-->!-->답변 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 텍스트 보고싶네요.
답변을 작성하시기 전에 로그인 해주세요.