SOURCE

var welcomeString='Welcome';
document.write(welcomeString+'</br>');
document.write(welcomeString.length+'</br>');
//大写(函数的调用)
document.write(welcomeString.toUpperCase()+'</br>');
//小写
document.write(welcomeString.toLowerCase()+'</br>');
document.write("<br>----------------------</br>");
//获取字符串中的某个字符
document.write(welcomeString.charAt(2)+'</br>');
//获取字符串中的某几个字符
document.write(welcomeString.substring(3)+'</br>');
document.write(welcomeString.substring(0,2)+'</br>');
document.write("<br>----------------------</br>");
//将字符串中的某个字符串进行替换
var sentence='We are family in We We';
writeDocument(sentence);
writeDocument(sentence.replace('We','You'));//返回一个值
//正则表达式(对字符串的全部出现的字符串进行替换global)
var sentence1='We are family in family';
writeDocument(sentence1);
//正则表达式(/字符串/global)
writeDocument(sentence1.replace(/family/g,'cool'));
document.write("<br>----------------------</br>");
//对字符串进行切割(返回一个数组,用逗号隔开)
var spritsentence='we have fun in our class';
writeDocument(spritsentence);
//对字符串进行切割(分隔符:空格)
writeDocument(spritsentence.split(' '));
//对单词进行切割(空字符)
writeDocument(welcomeString.split(''));
//将句子进行切割
var spritsentence1='We have fun in our class.Do you have fun in your class?';
writeDocument(spritsentence1);
writeDocument(spritsentence1.split('.')+'</br>');
document.write("<br>----------------------</br>");
//获取字符串中第一个出现单词的第一个字母的位置
writeDocument(spritsentence1.indexOf('class'));
//未找到返回-1
writeDocument(spritsentence1.indexOf('Class'));
//获取字符串中最后出现单词的第一个字母的位置
writeDocument(spritsentence1.lastIndexOf('class'));
//writeDocument(spritsentence1.match('class'));
//writeDocument(spritsentence1.search('class'));
document.write("<br>----------------------</br>");
//案例:统计字符串的个数
function countChar(stringValue,char){
    var count=0;
    for(i=0;i<stringValue.length;i++){
        if(stringValue.toLowerCase().charAt(i)==char){
        ++count;
        
    }
    }   
    return count;
} 
var string1='Speak English in you class';
writeDocument('There are '+countChar(string1,'s')+' in sentence');
document.write("<br>----------------------</br>");
//作用:用于检查其参数是否为非数字值
//参数值:NaN、字符串、对象、undefined等非数字值 返回true,否则返回false
writeDocument(isNaN('abcde'));
writeDocument(isNaN('NaN'));
writeDocument(isNaN(1234));
writeDocument(isNaN('abc123'));
writeDocument(isNaN('123abc'));
writeDocument(isNaN());

//用于换行
function writeDocument(variable) {
    document.write(variable + "<br/>");
} 
console 命令行工具 X clear

                    
>
console