SOURCE

var pythonString="python";

document.write("----------------"+"<br/>");

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

document.write("----------------"+"<br/>");

document.write(pythonString.toLowerCase()+"<br/>");
document.write(pythonString.toUpperCase()+"<br/>");

document.write("----------------"+"<br/>");

document.write(pythonString.charAt(2)+"<br/>");
document.write(pythonString.charAt(5)+"<br/>");

document.write("----------------"+"<br/>");

document.write(pythonString.substring(3)+"<br/>");
document.write(pythonString.substring(0,2)+"<br/>");

document.write("----------------"+"<br/>");

var sentence="I HATE JavaScript I hate javascript";
document.write(sentence+"<br/>");
document.write(sentence.replace("JavaScript","python")+"<br/>");
document.write(sentence.replace(/JavaScript/g,"python")+"<br/>");

document.write("----------------"+"<br/>");

document.write(sentence.split(" ")+"<br/>");
document.write(pythonString.split("")+"<br/>");
document.write(sentence.split("")+"<br/>");
document.write(sentence.split(".")+"<br/>");

document.write("----------------"+"<br/>");

document.write(sentence.indexOf("hate")+"<br/>");
document.write(sentence.lastIndexOf("hate")+"<br/>");
document.write(sentence.match("hate")+"<br/>");
document.write(sentence.match(/hate/g)+"<br/>");
document.write(sentence.search(/hate/g)+"<br/>");

document.write("----------------"+"<br/>");
function countChar(stringToCount, char) {
    var charCount = 0;
    
    for(var i=0;i<stringToCount.length;i++){
        if(stringToCount.charAt(i).toLowerCase()==char){
            ++charCount;
        }
    }
    return charCount;
}
var stringToCount = "Can you can a can as a Canner can can a can";
document.write("There are " + countChar(stringToCount, "c") + " c in " + stringToCount);

document.write("----------------"+"<br/>");
console 命令行工具 X clear

                    
>
console