- ES6 教程
- ES6 - 首頁
- ES6 - 概述
- ES6 - 環境
- ES6 - 語法
- ES6 - 變數
- ES6 - 運算子
- ES6 - 決策制定
- ES6 - 迴圈
- ES6 - 函式
- ES6 - 事件
- ES6 - Cookie
- ES6 - 頁面重定向
- ES6 - 對話方塊
- ES6 - Void 關鍵字
- ES6 - 頁面列印
- ES6 - 物件
- ES6 - 數字
- ES6 - 布林值
- ES6 - 字串
- ES6 - Symbol
- ES6 - 新的字串方法
- ES6 - 陣列
- ES6 - 日期
- ES6 - 數學
- ES6 - 正則表示式
- ES6 - HTML DOM
- ES6 - 迭代器
- ES6 - 集合
- ES6 - 類
- ES6 - Map 和 Set
- ES6 - Promise
- ES6 - 模組
- ES6 - 錯誤處理
- ES6 - 物件擴充套件
- ES6 - Reflect API
- ES6 - Proxy API
- ES6 - 驗證
- ES6 - 動畫
- ES6 - 多媒體
- ES6 - 除錯
- ES6 - 影像地圖
- ES6 - 瀏覽器
- ES7 - 新特性
- ES8 - 新特性
- ES9 - 新特性
- ES6 有用資源
- ES6 - 快速指南
- ES6 - 有用資源
- ES6 - 討論
ES6 - substr()
此方法返回從指定位置開始的字串中指定數量的字元。
語法
string.substr(start[, length]);
引數詳情
start − 開始提取字元的位置(一個介於 0 和字串長度減 1 之間的整數)。
length − 要提取的字元數
注意 − 如果start 為負數,則substr 將其用作字串末尾的字元索引。
返回值
substr() 方法根據給定的引數返回新的子字串。
示例
var str = "Apples are round, and apples are juicy.";
console.log("(1,2): " + str.substr(1,2));
console.log("(-2,2): " + str.substr(-2,2));
console.log("(1): " + str.substr(1));
console.log("(-20, 2): " + str.substr(-20,2));
console.log("(20, 2): " + str.substr(20,2));
輸出
(1,2): pp (-2,2): y. (1): pples are round, and apples are juicy. (-20, 2): nd (20, 2): d
廣告