Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

198
Visualizações
How to FormData append nested object

how can post this array with form append:

data = [
    {
        "title":"title 1",
        "subTitle": "subTitle 1",
        "productId": "[1,2,3]"
    },
    {
        "title":"title 2",
        "subTitle": "subTitle 1",
        "productId": "[4,5,6]"
    },
    {
        "title":"title 3",
        "subTitle": "subTitle 1",
        "productId": "[7,8,9]"
    }
]

If I submit data as here : formData.append("data", JSON.stringify(this.data); I cannot get just id key in value productId

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Once your array has been "stringify" you need to use JSON.parse to access individual key

const obj = JSON.parse('{"name":"John", "age":30, "city":"New York"}');
<p id="demo"></p>

<script>
document.getElementById("demo").innerHTML = obj.name;
</script>

Also looking at your array it you will have to do it like this with the array key

obj[0].productId
obj[1].productId
obj[2].productId
obj[3].productId

and from that point extract the array

 for (let i  = 0 ; i <  obj[3].productId.length ; i++)
{ 
 console.log(obj[3].productId[i]);

 }

Let me know if you need more info on it

about 4 years ago · Juan Pablo Isaza Relatório

0

You can try this-

data.forEach(item => {
            formData.append(`data[]`, JSON.stringify(item));
        });

and in the backend, you need to parse it for sending to the front end.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda