07JavaScript数组与字符串对象

JavaScript数组与字符串对象


5.1.1数组(Array)对象

    <script>

       //声明一个数组并赋值;

       var arr = new Array("aa","bb","cc");

       //输出数组元素的个数;

       document.write(arr.length+"<br>");

       //颠倒数组中元素的顺序,反向排列;

       document.write(arr.reverse()+"<br>");

       //移除数组中的第一个元素并返回该元素;

       document.write(arr.shift()+"<br>");

       //移除数组中的最后一个元素并返回该元素;

       document.write(arr.pop()+"<br>");

    </script>

5.1.2字符串(String)对象

    <script>

       //声明一个字符串并赋值;

       var str = "String";

       //输出字符串的长度;

       document.write(str.length+"<br>");

       //把字符串中的文本变成划掉字体;

       document.write(str.strike()+"<br>");

       //把字符串中的文本变成斜字体;

       document.write(str.italics()+"<br>");

        //把字符串中的文本变成小字体;

       document.write(str.small()+"<br>");

       //把字符串中的文本变成大字体;

       document.write(str.big()+"<br>");

       //把字符串中的文本变成黑字体;

       document.write(str.bold()+"<br>");

       //把字符串中的文本变成闪烁字体;

       document.write(str.blink()+"<br>");

       //把字符串中的文本变成固定间距字体,即电报形式;

       document.write(str.fixed()+"<br>");

    </script>

字符串(String)对象的常用方法

anchor、link

创建书签链接,相当于<A name=…>, 格式为String.anchor()

创建超链接,相当于<A href=…>,格式为String.link(URL)

big、small、italics、bold、blink、sup、sub、fontsize 、fontcolor  

创建字符显示格式,相当于<BIG>、<B>等HTML标记。

toLowerCase、toUpperCase

字符串大小写转换

indexOf、lastindexOf

返回指定子字符串在字符串中第一次出现的左、右索引位置

substring(start,end)

返回从start开始到end的子字符(不包括end位置的字符)

charAt

返回某字符串中指定的子字符串

猜你喜欢

转载自www.cnblogs.com/Aha-Best/p/10944771.html
今日推荐