If you mean a : instead of a =>, then you can achieve this with a filter and map, or you could do it with a reduce. The second method would be “faster”, but the first method could be argued to be more readable.
Yes, absolutely. It would just be with a :, not =>. The latter is the notation for an arrow function. Firstly that is not a valid arrow function. But you can have functions as values in a JS object. But functions are not a valid JSON type (but maybe that does not matter here, if you’re converting to a JS object).
We’re not really a “solve your problem” platform, this is a “help people learn” platform.
If you want to work with JS, then you should learn it. There is a button in the upper left, Visit the Curriculum.
And I still don’t know what you want - you have two “textbox2” names with different values. It’s not clear how that is supposed to handle.
I thought JSON was the best way to be able to save it to the database.
Sure, that is a great way to store data. You can store JS object data in JSON to make it easier to store in a file, etc. You can’t have true JSON in JS but you can have a JSON encoded string. But we have to remember that JSON is a subset of a JS object - all JSON objects can be converted to a JS object, but not all JS objects cannon necessarily be converted to a JSON object.
But at the very least, this should be easily solvable with a for loop.
Learn that, and give it a go. If your attempt doesn’t work, post it and we’ll try to help you figure out why it doesn’t work.
We usually do not just delete threads especially not if someone has taken the time to help and because they may contain helpful information to others.
Did you not get anything useful out of the thread so far?
Not so sure using serializeArray is the best way to do this if you need the element types.
Sure you will know what the type is based on its position in the array, input is even, and textarea is odd. So you can do it using a map by checking if the index is even or odd and creating a new object with the keys and value you want.
But that does seem like a poor abstraction to rely on. I might look into using the FormData API instead.
As said we are here to teach so just posting solution code isn’t really the main purpose of the forum, but here is a very crude example of what I mean by using the index just in case it’s unclear. I’m sure it can be improved or be done differently. I may also have misunderstood what you are trying to do. https://jsfiddle.net/c8fqgsLw/
By the way, the elements must have a name attribute for serializeArray to work and your starting elements do not.