简体   繁体   中英

How to convert an Array of objects single JSON Document/Object

I'm trying to convert an array objects to a JSON Document

My array is

var images = [{"id1":{"type":"image/png",data:blob}}, {...}, {..}  ...];

And I want to convert it into a Json Document containing all the elements of array

ex:

var someOtherObject = {
"_id":"12345",
"name":"test",
"_attachments":{images[0],images[1]...}

the array size is dynamic, So i can't hardcode them as i did above.

Thanks

If you _attachments is dynamic, it should be an array of objects inside your main object.

var images = [{"id1":{"type":"image/png",data:blob}}, {...}, {..}  ...];

var someOtherObject = {
"_id":"12345",
"name":"test",
"_attachments":images

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM