This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
getAll() method of the
Headers interface used to return an array of all the values of a header within a
Headers object with a given name; in newer versions of the Fetch spec, it has been deleted, and
Headers.get() has been updated to fetch all header values instead of only the first one.
If the requested header doesn't exist in the
Headers object, it returns an empty array.
- The name of the HTTP header whose values you want to retrieve from the
Headersobject. If the given name is not the name of an HTTP header, this method throws a
Creating an empty
Headers object is simple:
var myHeaders = new Headers(); // Currently empty
You could add a header to this using
Headers.append, then retrieve it using
myHeaders.append('Content-Type', 'image/jpeg'); myHeaders.getAll('Content-Type'); // Returns [ "image/jpeg" ]
If the header has multiple values associated with it, the array will contain all the values, in the order they were added to the Headers object:
myHeaders.append('Accept-Encoding', 'deflate'); myHeaders.append('Accept-Encoding', 'gzip'); myHeaders.getAll('Accept-Encoding'); // Returns [ "deflate", "gzip" ]
Headers.get to return only the first value added to the
BCD tables only load in the browser