I would like to make an API call with the data formatted like this.
[{"Id":10, “FolderID”:22},{"Id":12, “FolderID”:22}]
I have these different data sources below: (using redux)
const FolderId = indexes.currentFolder.id;
This is a constant value
const documentsId = indexes.copyDocuments;
this is the format of 8, 9 , 10
I tried to implement it by looping through the documents array with a foreach.
The only way i know how to attach the data is with an array but this creates a new array of each loop with is not what i want.
const data = [];
documentsId.forEach(function(doc){
data.push(`"Id":${doc},"FolderID":${FolderId}`)
})
Does anyone know a way of doing this? Thanks.
var tmp = {}; tmp.Id = doc.Id; tmp.FolderId = doc.FolderId; data.push(tmp);FolderIdin the followingdata.push("Id":${doc},"FolderID":${FolderId}). If you're pushing an object to your array you can usedata.push({"Id":`${doc}`,"FolderID":`${FolderId}`}.