buf.includes(value[, byteOffset][, encoding])
value<string> | <Buffer> | <Uint8Array> | <integer> 要查找什么。byteOffset<integer> 在buf中从哪里开始搜索。如果为负,则偏移量从buf的末尾计算。默认值:0。encoding<string> 如果value是字符串,则这是它的编码方式。默认值:'utf8'。- 返回:<boolean> 如果在
buf中找到了value,则为true,否则为false。
等同于 buf.indexOf() !== -1。
🌐 Equivalent to buf.indexOf() !== -1.
import { Buffer } from 'node:buffer';
const buf = Buffer.from('this is a buffer');
console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
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)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: falseconst { Buffer } = require('node:buffer');
const buf = Buffer.from('this is a buffer');
console.log(buf.includes('this'));
// Prints: true
console.log(buf.includes('is'));
// Prints: true
console.log(buf.includes(Buffer.from('a buffer')));
// Prints: true
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)));
// Prints: true
console.log(buf.includes('this', 4));
// Prints: false