Skip to content

doc: update buffer examples to use subarray instead of slice #58912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions doc/api/buffer.md
Original file line number Diff line number Diff line change
Expand Up @@ -1979,7 +1979,7 @@ console.log(b.toString());
// Fill a buffer with empty string
const c = Buffer.allocUnsafe(5).fill('');

console.log(c.fill(''));
console.log(c);
// Prints: <Buffer 00 00 00 00 00>
```

Expand All @@ -1996,7 +1996,7 @@ console.log(b.toString());
// Fill a buffer with empty string
const c = Buffer.allocUnsafe(5).fill('');

console.log(c.fill(''));
console.log(c);
// Prints: <Buffer 00 00 00 00 00>
```

Expand Down Expand Up @@ -2084,7 +2084,7 @@ console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
console.log(buf.includes(Buffer.from('a buffer example').subarray(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false
Expand All @@ -2105,7 +2105,7 @@ console.log(buf.includes(97));
// Prints: true (97 is the decimal ASCII value for 'a')
console.log(buf.includes(Buffer.from('a buffer example')));
// Prints: false
console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
console.log(buf.includes(Buffer.from('a buffer example').subarray(0, 8)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false
Expand Down Expand Up @@ -2160,7 +2160,7 @@ console.log(buf.indexOf(97));
// Prints: 8 (97 is the decimal ASCII value for 'a')
console.log(buf.indexOf(Buffer.from('a buffer example')));
// Prints: -1
console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
console.log(buf.indexOf(Buffer.from('a buffer example').subarray(0, 8)));
// Prints: 8

const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
Expand All @@ -2186,7 +2186,7 @@ console.log(buf.indexOf(97));
// Prints: 8 (97 is the decimal ASCII value for 'a')
console.log(buf.indexOf(Buffer.from('a buffer example')));
// Prints: -1
console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
console.log(buf.indexOf(Buffer.from('a buffer example').subarray(0, 8)));
// Prints: 8

const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
Expand Down
Loading