Skip to main content
Active reading [<https://en.wikipedia.org/wiki/ECMAScript#6th_Edition_-_ECMAScript_2015>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

For input fields you could use ECMA6ECMAScript 6 like the following:

Get your form in a constant:

const form = document.querySelector('form') 

Grab all values:

Object.values(form).reduce((obj,field) => { obj[field.name] = field.value; return obj }, {}) 

AboveThe above snippet will produce an object with the input name as the key and its value.

For input fields you could use ECMA6 like following:

Get your form in a constant

const form = document.querySelector('form') 

Grab all values:

Object.values(form).reduce((obj,field) => { obj[field.name] = field.value; return obj }, {}) 

Above snippet will produce an object with the input name as key and its value.

For input fields you could use ECMAScript 6 like the following:

Get your form in a constant:

const form = document.querySelector('form') 

Grab all values:

Object.values(form).reduce((obj,field) => { obj[field.name] = field.value; return obj }, {}) 

The above snippet will produce an object with the input name as the key and its value.

Source Link
Shairon Toledo
  • 2.1k
  • 1
  • 16
  • 18

For input fields you could use ECMA6 like following:

Get your form in a constant

const form = document.querySelector('form') 

Grab all values:

Object.values(form).reduce((obj,field) => { obj[field.name] = field.value; return obj }, {}) 

Above snippet will produce an object with the input name as key and its value.