buf.includes(value[, byteOffset][, encoding])
-
value<string> | <Buffer> | <Uint8Array> | <integer> 要搜索的内容。¥
value<string> | <Buffer> | <Uint8Array> | <integer> What to search for. -
byteOffset<integer> 开始搜索buf的位置。如果为负数,则从buf的末尾开始计算偏移量。默认值:0。¥
byteOffset<integer> Where to begin searching inbuf. If negative, then offset is calculated from the end ofbuf. Default:0. -
encoding<string> 如果value是字符串,则这就是它的编码。默认值:'utf8'。¥
encoding<string> Ifvalueis a string, this is its encoding. Default:'utf8'. -
返回:<boolean> 如果在
buf中找到value,则为true,否则为false。¥Returns: <boolean>
trueifvaluewas found inbuf,falseotherwise.
相当于 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