Response.prototype.text
Takes a Response stream and reads it to completion, returning the result as a string
Syntax
response.text()Return Value
A Promise that resolves to a string
Examples
const response = await fetch('/readme.txt')
const text = await response.text()
console.log(text)async function fetchHTML(url: string): Promise<string> {
const res = await fetch(url)
if (!res.ok) throw new Error(`HTTP ${res.status}`)
return res.text()
}const res = await fetch('/api/health')
const body = await res.text()
try {
const data = JSON.parse(body)
console.log(data)
} catch {
console.log('Plain text:', body)
}Understanding Response.prototype.text
The Response.prototype.text method in JavaScript takes a Response stream and reads it to completion, returning the result as a string. It belongs to the Response object and is one of the most widely used methods for working with response values in modern JavaScript and TypeScript applications.
The method signature is response.text(). When called, it returns a promise that resolves to a string. Understanding when and how to use text() helps you write more expressive, readable code.
Common use cases for Response.prototype.text include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like fetch-response-json, fetch-response-blob, fetch-response-arraybuffer, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Response.prototype.text is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Response.prototype.jsonTakes a Response stream and reads it to completion, parsing the result as JSON
Response.prototype.blobTakes a Response stream and reads it to completion, returning the result as a Blob
Response.prototype.arrayBufferTakes a Response stream and reads it to completion, returning the result as an ArrayBuffer
More Response Methods
Other methods in the Response object
Related Tools
More Response Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.