大家好,我开始学习 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"));
就是这样,我知道这很简单,但我认为这个字符串操作很酷:)
以上是使用 VSCode 的基本 Javascript的详细内容。更多信息请关注PHP中文网其他相关文章!