gpt4 book ai didi

javascript - 对象数组到数组数组作为字符串

转载 作者:行者123 更新时间:2023-12-01 01:58:27 25 4
gpt4 key购买 nike

我有 JSON 对象 oAtt 声明为

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

MessageStore.message() 在此处可用的代码中声明:https://github.com/RainLoop/rainloop-webmail/blob/master/dev/Model/Message.js

当我将其输出到控制台时,oArr 的形式为 [object Object],[object Object]。在stringify之后,它是:

 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}
]

当我尝试将该对象转换为值数组时,它出现为

sample.pdf,test4.jpg

使用下面的代码:

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

当我直接以 oAtt[0].fileName 形式访问它时,我将获取文件名值。此外,当我从主代码(仅声明了 oAttmap 代码行)运行它时,它应该按预期工作。

有什么线索可能是错的吗?

最佳答案

我无法重现您的问题。 oArr 是什么?您正在谈论代码中的 oAttaAtt

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);

关于javascript - 对象数组到数组数组作为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50805989/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com