Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow FormData constructor to accept array or object too #3633

Closed
jimmywarting opened this issue Apr 18, 2018 · 1 comment
Closed

Allow FormData constructor to accept array or object too #3633

jimmywarting opened this issue Apr 18, 2018 · 1 comment

Comments

@jimmywarting
Copy link

Like the URLSearchParams allow the FormData constructor able to accept a iterable array or object
instead of having to manually append everything

Current way of solving things:

var data = ['foo', 'bar']
var data = {foo: 'bar'}

var fd = new FormData()

for (let [key, val] of new URLSearchParams(data)) {
  fd.append(key, val)
}

// or one-liner 
new URLSearchParams(data).forEach(args => fd.append(...args))

Suggested way

var data = ['foo', 'bar']
var data = {foo: 'bar'}

var fd = new FormData(data)
@annevk
Copy link
Member

annevk commented Apr 18, 2018

This doesn't seem entirely unreasonable, but please file it at https://github.com/whatwg/xhr/issues/new as that's where FormData is defined. Thanks!

@annevk annevk closed this as completed Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants