JavaScript String常用方法和属性

  在JavaScript中,字符串是不可变的,如果使用索引对字符串进行修改浏览器不会报错,但也没有任何效果。JavaScript提供的这些方法不会修改原有字符串的内容,而是返回一个新的期望的字符串。

 

 一、string中的常用属性

 

 1. length

说明:

  字符串的长度属性,一直保持跟踪着该字符串中包含的字符数。

 

 

 二、string中的常用方法

 

 1. toLowerCase() 和 toUpperCase()

说明:

  toLowerCase(): returns a copy of the string with its letters converted to lowercase. Numbers, symbols, and other characters are not affected.

  toUpperCase(): returns a copy of the string with its letters converted to capitals. Numbers, symbols, and other characters are not affected.

 

 2. trim()

说明:

  returns a copy of the string with beginning and ending whitespace characters removed.

 

posted @ 2019-04-12 22:43  路漫漫我不畏  阅读(437)  评论(0)    收藏  举报