How to post Axios data has array inside?

Viewed 25

I want to post files to groups. by storing the group id I want to send files to groupsFinal, but axios.post() will only post to the first array of groupsFinal, I tried for loop but it fails axios post.

let groups = [{id:"a001", groupName:"Group101"},{id:"a002", groupName:"Group202"}]
let groupsFinal = [];
  for (let a = 0; a < groups.length; a++) {
    let d = JSON.parse(JSON.stringify(groups[a]));
    d.img = null;
    groupsFinal.push(d);
  }
  let p = {
    fileId: "file_001",
    groups: groupsFinal, // array[]
  };
return new Promise((resolve, reject) => {
    axios
      .post("/shareFileToGroup", p, {
        headers: {
          "Content-Type": "application/json"
        },
      })
      .then(function (response) {
        resolve("success");
      })
      .catch(function (error) {
        reject("error");
      })
      .finally(function () {
        // always executed
      });
  });
0 Answers
Related