I am not sure if I am missing something or that is doesnt work like I think it does. I have some form data that I want to split. To do this I thought I could create another object with the values i want to like this:
let data = $('form').serializeArray();
let answers = {};
data.forEach(function(element) {
// check if the element contains a answer input value
if(element.name.indexOf('answer') !== -1) {
answers[element.name] = element.value;
}
});
console.log($('form').serialize());
// output: answer%5B1%5D=1&answer%5B2%5D=2&answer%5B4%5D=3&answer%5B3%5D=4&sort=relevance&query=&area=..... etc
console.log(answers.serialize());
// output: is not a function.
So again. I thought you could serialize a object to a string for data storage like I do with the form data.
Can someone explain to me what i am doing wrong and/or why serialize does not work?