JavaScript padStart()
padStart()會用第二個引數中指定字串,在當前字串頭部不斷填充,直到達到第一個引數中指定的目標長度。
此方法是ES2017新增。
語法結構:
[JavaScript] 純文字檢視 複製程式碼str.padStart(targetLength [, padString])
引數解析:
(1).targetLength:必需,當前字串需要填充到的目標長度。如果當前字串原本就達到了該長度,那麼該方法什麼都不會做,直接返回原字串。
(2).padString:可選,填充字串。如果在填充過程中發現用不完這一整個填充字串,則優先用左側部分,能用多少用多少。該引數為可選引數,預設值為空格 " " (U+0020)。
程式碼例項:
[JavaScript] 純文字檢視 複製程式碼執行程式碼console.log("ant".padStart(10)); console.log("ant".padStart(10, "foo")); console.log("ant".padStart(6, "123465"));
相關文章
- 字串— padStart() 和 padEnd()字串
- Vue學習(一)過濾器以及padStart和padEndVue過濾器
- JavaScript高階:JavaScript物件導向,JavaScript內建物件,JavaScript BOM,JavaScript封裝JavaScript物件封裝
- javaScript系列[06]-javaScript和thisJavaScript
- [Javascript] How javascript read the property?JavaScript
- javaScript系列[05]-javaScript和JSONJavaScriptJSON
- “This” is For JavaScriptJavaScript
- This in JavaScriptJavaScript
- JavaScript -"this"JavaScript
- JavaScriptJavaScript
- javascript ??JavaScript
- 44 道 JavaScript 難題(JavaScript Puzzlers!)JavaScript
- [Javascript] Understanding JavaScript Proxies with Symbol.toPrimitiveJavaScriptSymbolMIT
- JavaScript 教程之JavaScript常用框架簡介JavaScript框架
- [Javascript] Perform Set Operations using JavaScript Set MethodsJavaScriptORM
- javascript — == vs ===JavaScript
- JavaScript selectedIndexJavaScriptIndex
- JavaScript deleteCell()JavaScriptdelete
- JavaScript lastElementChildJavaScriptAST
- JavaScript hasAttribute()JavaScript
- JavaScript getAttributeNode()JavaScript
- JavaScript replaceChild()JavaScript
- JavaScript remove()JavaScriptREM
- JavaScript appendChild()JavaScriptAPP
- JavaScript deleteRow()JavaScriptdelete
- JavaScript clientYJavaScriptclient
- JavaScript之thisJavaScript
- JavaScript isFinite()JavaScript
- JavaScript toggle()JavaScript
- JavaScript Boolean()JavaScriptBoolean
- JavaScript escape()JavaScript
- JavaScript parseFloat()JavaScript
- JavaScript unescape()JavaScript
- JavaScript call()JavaScript
- JavaScript bind()JavaScript
- JavaScript previousElementSiblingJavaScript
- JavaScript preventDefault()JavaScript
- JavaScript insertRow()JavaScript