forEach문 질문입니다. 채택완료
</p>
<p>files = </p>
<p>{ 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 } } }</p>
<p>
files 안에는 {
attachFile1 : File{key:value, key:value }
attachFile2 : File{key:value, key:value }
.
.
.
attachFile + N : File{key:value, key:value }
}
이런식으로 값이 담겨있는데
여기에서
files.forEach()
하면 type에러가 발생하네요..
위 데이터를 저는 아래처럼 하고 싶습니다.
</p>
<p>[{ path: 'client\\assets\\upload\\qna\\file\\upload_1f221cf5ebd060a9743a10a6299c5fc6.jpg',
name: 'KakaoTalk_20171024_200451916.jpg',
type: 'image/jpeg'},</p>
<p>{</p>
<p>path: 'client\\assets\\upload\\qna\\file\\upload_16c11c425a7190f49c0f72fb30c57e82.jpg',
name: '7.jpg',
type: 'image/jpeg'</p>
<p>}</p>
<p>.</p>
<p>.</p>
<p>.</p>
<p> </p>
<p>]</p>
<p>
도와주세요 ㅠㅠ
답변 2개
수정! 사용 사능하시길 바랍니다.
</strong></p>
<p><strong><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 }}}</strong></p>
<p><strong>},
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 }}}</strong></p>
<p><strong>}
}]</strong></p>
<p><strong>
var newArr = [];
var newFile = [];
files.forEach(function(att, i) {
newArr = att;
});</strong></p>
<p><strong>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;
}
}</strong></p>
<p>
<strong>console.log(newFile);
</script></strong></p>
<p><strong>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
^^