var myCountry="india";
console.log( myCountry);
myCountry.substring(0,3)
console.log( myCountry);
这里我声明了一个变量myCountry.I已经将值作为india.Used console.log来打印变量。用过的console.log打印出myCountry的前三个字母。 编译器抛出的错误没有将myCountry的长度记录到控制台。
答案 0 :(得分:2)
substring
不会改变原始变量,它会返回结果,所以:
myCountry = myCountry.substring(0, 3);
console.log(myCountry); // "ind"
答案 1 :(得分:1)
试试这个:
myCountry = myCountry.substring(0,3);
答案 2 :(得分:1)
注意:substring()方法不会更改原始字符串。
myCountry = myCountry.substring(0,3);