SOURCE

function writeDocument(variable) {
    document.write(variable + "<br/>");
} 


var welcomeString="Welcome";
writeDocument(welcomeString);
writeDocument(welcomeString.length);
writeDocument(welcomeString.toLowerCase());
writeDocument(welcomeString.toUpperCase());
writeDocument(welcomeString.charAt(2));
writeDocument(welcomeString.charAt(6));
writeDocument(welcomeString.substring(3));
writeDocument(welcomeString.substring(0,2));

var sentence="We have fun in our class. Do you have fun in your class?"
writeDocument(sentence);
//writeDocument(sentence.replace("We","You"));
writeDocument(sentence.replace("class","programming class"));
writeDocument(sentence.replace(/class/g,"programming class"));


var splitSentence="We have fun in our class.";
writeDocument(splitSentence);
writeDocument(splitSentence.split(" "));
writeDocument(welcomeString.split(""));
writeDocument(sentence.split(""));

writeDocument(sentence.indexOf("class"));
writeDocument(sentence.lastIndexOf("class"));

var a="Javascript";
b=1;
c=" ";
writeDocument(isNaN(a));
writeDocument(isNaN(b));
writeDocument(isNaN(c));

function countChar(stringValue, char) {
    var charCount = 0;
    for(var i=0;i<stringValue.length;i++){
        if(stringValue.charAt(i).toLowerCase()==char){
            ++charCount;
        }
    }

    return charCount;
} 
var stringValue="Can you can a can as a Canner can can a can";
writeDocument("There are "+countChar(stringValue,"c")+"'c' in this sentence.");
console 命令行工具 X clear

                    
>
console