Put data in JSON using jQuery

I am creating a JSON array from the presented data in the form, but this script is broken and cannot understand what is causing it!

Any ideas?

Jquery:

var canvas = []; var Submission = {}; var Answer = {}; $('.question-holder > input').each(function(){ answer = $(this).val() input_name = $(this).attr('name') label = $(this).closest('li').find('label') // Push everything into the questions array Answer.push({ Answers: answer, Input_Name: input_name, Label: label }); }); $('.submit-holder > input').each(function(){ answer = $(this).val() input_name = $(this).attr('name') label = $(this).closest('li').find('label') Submission.push({ Question: label, Input_Name: input_name, Submitted_data: answer }); }); canvas.push({ Submission: Submission, Answers: Answer, Motivation: $('.motivation').val() }); json = JSON.stringify({json: canvas}, null, "\t"); 
-one
source share
1 answer

The problem is with the declaration:

 var Submission = {}; var Answer = {}; 

They must be such arrays that objects (hash) do not have push() defined

 var Submission = []; var Answer = []; 
+2
source

Source: https://habr.com/ru/post/1500384/


All Articles