
- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送電子郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 限制資料
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用程式模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - Buffer.byteLength() 方法
NodeJS 的 Buffer.byteLength() 方法用於計算緩衝區物件的位元組長度。
語法
以下是 Node.JS Buffer.byteLength() 方法 的語法:
Buffer.byteLength( string, encoding )
引數
此方法接受兩個引數。具體說明如下。
string −(必填) 將計算其長度的物件。支援的型別包括:字串、Buffer、TypedArray、DataView、ArrayBuffer
encoding −:(可選)。如果給定的物件是字串,則必須指定編碼。預設情況下,使用的編碼為“utf-8”。
返回值
Buffer.byteLength() 方法將返回緩衝區物件的位元組長度。
示例
此示例將使用 NodeJS Buffer.from() 方法建立一個緩衝區,並使用 Buffer.byteLength() 查詢其長度。
const buf = Buffer.from('Hello World'); console.log("The length is :"+Buffer.byteLength(buf));
輸出
The length is :11
示例
此示例將使用 Buffer.alloc() 方法建立一個緩衝區,並使用 Buffer.byteLength() 查詢其長度。
const buf = Buffer.alloc(15); console.log("The length is :"+Buffer.byteLength(buf));
輸出
The length is :15
示例
此示例將使用 Buffer.allocUnsafe() 方法建立一個緩衝區,並使用 Buffer.byteLength() 查詢其長度。
const buf = Buffer.allocUnsafe(15); console.log("The length is :"+Buffer.byteLength(buf));
輸出
The length is :15
示例
您可以直接在 Buffer.byteLenght() 中使用字串物件,如下所示。
console.log("The length is :"+Buffer.byteLength('Hello World'));
輸出
The length is :11
nodejs_buffer_module.htm
廣告