0

I have JSON object oAtt declared as

var oAtt = MessageStore.message().attachments();

MessageStore.message() is declared in the code available here: https://github.com/RainLoop/rainloop-webmail/blob/master/dev/Model/Message.js

When I output it to the console oArr came as [object Object],[object Object]. After stringify it came as:

 var oAtt = [
    {"sModelName":"AttachmentModel","disposables":[],"mimeType":"application/pdf","fileName":"sample.pdf","fileNameExt":"pdf","fileType":"pdf","description":null,"estimatedSize":19333,"friendlySize":"19KB","isInline":false,"isLinked":false,"isThumbnail":false,"cid":"","cidWithOutTags":"","contentLocation":"","download":"zyfTZvzczVW6cqlcsIrm3ycmY5soz3DzK5sZhjnSOwaW0wnwGwHtqBvPeo8nVpiWD4yKVIPvAPauJHZufHGRG0Eb4MRmBpkGlvsDGP-gz3CnVp4GorN_xXCI0Gkd2I93IySKMy5iXRt-wML9wxLwTZcrOMLyPp-Kr6b0GlzlHuvk3RqEXRqSlCQTX5piRO6AaRYeMKeq8PSJcId1grMYzFpCnjVSoW_Zj7yTGAsy-D_mzFoCmBdksCweEqPdGhFYFkukblXzaZiTSNGTj1xYOvMIN4XXUZtU0EAPoQ9EFxfPWY_-1Siyge0Gks2zbGs3myxXJg..","folder":"INBOX","uid":"22","mimeIndex":"2","framed":false},
    {"sModelName":"AttachmentModel","disposables":[],"mimeType":"image/jpeg","fileName":"test4.jpg","fileNameExt":"jpg","fileType":"image","description":null,"estimatedSize":26326,"friendlySize":"26KB","isInline":false,"isLinked":false,"isThumbnail":true,"cid":"","cidWithOutTags":"","contentLocation":"","download":"BN0gFmNTTOarHTn7bDrdaLxLQ-HmO36mmT8av0rwGMsO9XeBlK7OWBq4uiR5N3RkgjXBwwDtOcLBTPIx-354pFHsV2BigaNfpvFG7XlkFYyCsOwGQcNS2pR_U53ISNCnDV-bZYNjl6dc-XAPb71qOkkxn-XxWCtfqJl5ngPPQ67owcZUUfIv9ddSsGyX5PhMljxyMq6f_Cz6dp07Xeaex89ED35VTqyJe4C1MyAxq92fJlxBstcj7dM12YbRJzzWeS_B9t6g48mwh-0am6c28uxPAGYc_EP4C3VweITw7Q5uhTtNmycMksTu4CIVepYn","folder":"INBOX","uid":"22","mimeIndex":"3","framed":false}
    ]

When I have tried to convert that object to an array of values array it came as

sample.pdf,test4.jpg

using code below:

var aAtt = oAtt.map(({fileName}) => [fileName]);

When I will access it directly as oAtt[0].fileName I'm getting file name value. Also when I run it off the main code (only declared oAtt and map code line) it works as should.

Any clue what can be wrong?

2
  • FYI There isn't a single syllable of JSON in your question. JSON is a string notation that can be parsed into an object, while you already have a concrete object. Commented Jun 11, 2018 at 21:08
  • 1
    @PeterB I have re-phrased my question Commented Jun 11, 2018 at 22:46

2 Answers 2

2

I cannot reproduce your problem. What is oArr tho? You are talking about oAtt and aAtt in your code.

var oAtt = [{
    "sModelName": "AttachmentModel",
    "disposables": [],
    "mimeType": "application/pdf",
    "fileName": "sample.pdf",
    "fileNameExt": "pdf",
    "fileType": "pdf",
    "description": null,
    "estimatedSize": 19333,
    "friendlySize": "19KB",
    "isInline": false,
    "isLinked": false,
    "isThumbnail": false,
    "cid": "",
    "cidWithOutTags": "",
    "contentLocation": "",
    "download": "zyfTZvzczVW6cqlcsIrm3ycmY5soz3DzK5sZhjnSOwaW0wnwGwHtqBvPeo8nVpiWD4yKVIPvAPauJHZufHGRG0Eb4MRmBpkGlvsDGP-gz3CnVp4GorN_xXCI0Gkd2I93IySKMy5iXRt-wML9wxLwTZcrOMLyPp-Kr6b0GlzlHuvk3RqEXRqSlCQTX5piRO6AaRYeMKeq8PSJcId1grMYzFpCnjVSoW_Zj7yTGAsy-D_mzFoCmBdksCweEqPdGhFYFkukblXzaZiTSNGTj1xYOvMIN4XXUZtU0EAPoQ9EFxfPWY_-1Siyge0Gks2zbGs3myxXJg..",
    "folder": "INBOX",
    "uid": "22",
    "mimeIndex": "2",
    "framed": false
  },
  {
    "sModelName": "AttachmentModel",
    "disposables": [],
    "mimeType": "image/jpeg",
    "fileName": "test4.jpg",
    "fileNameExt": "jpg",
    "fileType": "image",
    "description": null,
    "estimatedSize": 26326,
    "friendlySize": "26KB",
    "isInline": false,
    "isLinked": false,
    "isThumbnail": true,
    "cid": "",
    "cidWithOutTags": "",
    "contentLocation": "",
    "download": "BN0gFmNTTOarHTn7bDrdaLxLQ-HmO36mmT8av0rwGMsO9XeBlK7OWBq4uiR5N3RkgjXBwwDtOcLBTPIx-354pFHsV2BigaNfpvFG7XlkFYyCsOwGQcNS2pR_U53ISNCnDV-bZYNjl6dc-XAPb71qOkkxn-XxWCtfqJl5ngPPQ67owcZUUfIv9ddSsGyX5PhMljxyMq6f_Cz6dp07Xeaex89ED35VTqyJe4C1MyAxq92fJlxBstcj7dM12YbRJzzWeS_B9t6g48mwh-0am6c28uxPAGYc_EP4C3VweITw7Q5uhTtNmycMksTu4CIVepYn",
    "folder": "INBOX",
    "uid": "22",
    "mimeIndex": "3",
    "framed": false
  }
];

var aAtt = oAtt.map(({fileName}) => [fileName]);

console.log(oAtt);
console.log(aAtt);

Sign up to request clarification or add additional context in comments.

3 Comments

When I run it as standalone it works as should but not in the main code.
Insert your whole code including the oArr definition please
I can't see anything you posted here inside of your github. Sorry but can't reproduce, you gotta target a specific code before to give it to us. Perfect would be a snippet reproducing the problem. Good luck
0

No clue why .map is not working when used in the main code but I have ended up with a code below

var aAtt = new Array();

for(var i=0;i<oAtt.length;i++)
{
   aAtt[i] = new Array();

   aAtt[i].push(oAtt[i].fileName);
   aAtt[i].push(oAtt[i].mimeType);
   aAtt[i].push(oAtt[i].download);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.