- ES6 教程
- ES6 - 主页
- ES6 - 概述
- ES6 - 环境
- ES6 - 语法
- ES6 - 变量
- ES6 - 运算符
- ES6 - 决策
- ES6 - 循环
- ES6 - 函数
- ES6 - 事件
- ES6 - Cookie
- ES6 - 页面重定向
- ES6 - 对话框
- ES6 - 无效关键字
- ES6 - 页面打印
- ES6 - 对象
- ES6 - 数字
- ES6 - 布尔值
- ES6 - 字符串
- ES6 - 符号
- ES6 - 新的字符串方法
- ES6 - 数组
- ES6 - 日期
- ES6 - 数学
- ES6 - 正则表达式
- ES6 - HTML DOM
- ES6 - 迭代器
- ES6 - 集合
- ES6 - 类
- ES6 - 地图和集合
- ES6 - 承诺
- ES6 - 模块
- ES6 - 错误处理
- ES6 - 对象扩展
- ES6 - 反射 API
- ES6 - 代理 API
- ES6 - 验证
- ES6 - 动画
- ES6 - 多媒体
- ES6 - 调试
- ES6 - 图像映射
- ES6 - 浏览器
- ES7 - 新特性
- ES8 - 新特性
- ES9 - 新特性
- ES6 有用资源
- ES6 - 快速指南
- ES6 - 有用的资源
- ES6 - 讨论
ES6 - Strings
The String object lets you work with a series of characters; it wraps JavaScript’s string primitive data type with a number of helper methods.
As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
Use the following syntax to create a String object.
var val = new String(string);
The string parameter is a series of characters that has been properly encoded. String.
String Properties
Following is a list of the properties of String object and its description.
Sr.No | Property & Description |
---|---|
1 | constructor
Returns a reference to the String function that created the object . |
2 | length
Returns the length of the string. |
3 | Prototype
The prototype property allows you to add properties and methods to an object . |
String Methods
Here is a list of the methods available in String object along with their description.
Sr.No | Method & Description |
---|---|
1 | charAt()
Returns the character at the specified index. |
2 | charCodeAt()
Returns a number indicating the Unicode value of the character at the given index. |
3 | concat()
Combines the text of two strings and returns a new string. |
4 | indexOf()
Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found. |
5 | lastIndexOf()
Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found. |
6 | localeCompare()
Returns a number indicating whether a reference string comes before or after or is the same as the given string in a sorted order. |
7 | match()
Used to match a regular expression against a string. |
8 | replace()
Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring. |
9 | search()
Executes the search for a match between a regular expression and a specified string. |
10 | slice()
Extracts a section of a string and returns a new string. |
11 | split()
Splits a String object into an array of strings by separating the string into substrings. |
12 | substr()
Returns the characters in a string beginning at the specified location through the specified number of characters. |
13 | substring()
Returns the characters in a string between two indexes into the string. |
14 | toLocaleLowerCase()
The characters within a string are converted to lower case while respecting the current locale. |
15 | toLocaleupperCase()
The characters within a string are converted to uppercase while respecting the current locale. |
16 | toLowerCase()
Returns the calling string value converted to lowercase. |
17 | toString()
Returns a string representing the specified object. |
18 | toUpperCase()
Returns the calling string value converted to uppercase. |
19 | valueOf()
Returns the primitive value of the specified object. |