[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ja/docs/Web/API/ReadableStream/from_static [Back]  [Original]

ReadableStream: from() - Web API | MDN

MDN Web Docs

View in English Always switch to English

ReadableStream: from()

Want more browser support for this feature? Tell us why.

Experimental:

ReadableStream.from() ReadableStream

ReadableStreamsNode.js readable

js
ReadableStream.from(anyIterable)

anyIterable

ReadableStream

TypeError

@@iterator @@asyncIterator

ReadableStream

ReadableStream

HTML

HTML <pre>

html
<pre id="log"></pre>

JavaScript

log() HTML

js
const logElement = document.getElementById("log");
function log(text) {
  logElement.innerText += `${text}\n`;
}

js
if (!ReadableStream.from) {
  log("ReadableStream.from() is not supported");
}

3 123 ReadableStream.from() ReadableStream

js
// 
const asyncIterator = (async function* () {
  yield 1;
  yield 2;
  yield 3;
})();

// ReadableStream 
const myReadableStream = ReadableStream.from(asyncIterator);

for ...await

js
consumeStream(myReadableStream);

// Iterate a ReadableStream asynchronously
async function consumeStream(readableStream) {
  for await (const chunk of myReadableStream) {
    // Do something with each chunk
    // Here we just log the values
    log(`chunk: ${chunk}`);
  }
}

ReadableStream.from()

ReadableStream

Array ReadableStream

JavaScript

ReadableStream.from() ReadableStream

js
// 
const vegetables = ["Carrot", "Broccoli", "Tomato", "Spinach"];

//  ReadableStream 
const myReadableStream = ReadableStream.from(vegetables);

Streams
# rs-from


Web Proxy Viewer  |  New URL  |  Original Page