Create nested object from inputs

I would like to create a nested object like below base on input forms. First key would be the name attribute, inside it would get required: true if the onput contains reqiuder attribute etc. I assume I need a nested foreach for that, I'm not sure. I added the code what I tried so far.

This is the object I like to create:

var obj = {
    'email.address': {
        required: true,
        email: true
     '': {
         required: false
     '': {
         required: true

This is the code I have at the moment:

var formInputs = $('input'),
    obj = {};

$.each(formInputs, function(key, value) {
  obj[] =;

<script src=""></script>
  <input type="email" name="email.address" placeholder="Email address" required />
  <input type="text" name="" placeholder="First name" />
  <input type="text" name="" placeholder="Last name" required />

Read more here:

Content Attribution

This content was originally published by levipadre at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: