This function provides an Array representation of an iterable object for use by JSON.stringify (24.3.2).
When the toJSON method is called, the following steps are taken:
- Let M be the this value.
- Let iterator be ? GetIterator(M)
- Let A be ! ArrayCreate(0).
- Let k be 0.
- Repeat
- Let Pk be ! ToString(k).
- Let next be ? IteratorStep(iterator).
- If next is false, then 1. Perform ? Set(A, "length", k, true). 1. Return A.
- Let nextValue be ? IteratorValue(next).
- Let defineStatus be CreateDataPropertyOrThrow(A, Pk, nextValue).
- If defineStatus is an abrupt completion, return IteratorClose(iterator, defineStatus).
- Increase k by 1.
The length property of the toJSON method is 0.
The initial value of the toJSON property is the same function object as the initial value of the Map.prototype.toJSON property.