Hello! 欢迎来到小浪资源网!



使用 VSCode 的基本 Javascript


使用 VSCode 的基本 Javascript

大家好,我开始学习 JavaScript,我分离了一些我设法做的事情:

let school = "javascript school"; let fullpackage = "js pro"; let projects = 4; let awesome = false;   console.log(school, fullpackage, projects, awesome);  

下面的用于显示类型:

let nome; nome = "eva" console.log(typeof(nome)); // 'string' nome = 123 console.log(typeof(nome)); // 'number' nome = {} console.log(typeof(nome)); // 'object'  

字符串大小:

let s1 = "melancia"; console.log("length de s1 = " + s1.length);    

访问每个角色:

let s1 = "abacaxi"; console.log(s1[0], s1[1], s1[2], s1[3], s1[4], s1[5], s1[6]);  

将所有内容都用大写字母:

let s1 = "melancia"; console.log(s1.touppercase());  

删除字符串开头的空格:

let s1 = "      melancia"; console.log(s1.trimstart());  

替换单词:

let s1 = "melancia"; console.log(s1.replace("melancia", "melão")); 

将字符串拆分为子字符串:

let s1 = "melancia é incrível"; console.log(s1.split(" "));  

在空格中添加破折号:

let s1 = "melancia é incrível"; console.log(s1.split(" ").join("-"));  

检查句子是否包含某些内容:

let s1 = "Melancia é incrível"; console.log(s1.includes("Mel")); 

就是这样,我知道这很简单,但我认为这个字符串操作很酷:)

相关阅读