diff --git a/lib/buffer.js b/lib/buffer.js index ca73549eba..f15de7d8ac 100644 --- a/lib/buffer.js +++ b/lib/buffer.js @@ -799,8 +799,8 @@ Buffer.prototype.write = function(string, offset, length, encoding) { Buffer.prototype.toJSON = function() { - if (this.length) { - const data = []; + if (this.length > 0) { + const data = new Array(this.length); for (var i = 0; i < this.length; ++i) data[i] = this[i]; return { type: 'Buffer', data };