javascript是否有替换字符串的一部分而不创建新字符串的方法? [英] Does javascript have a method to replace part of a string without creating a new string?
本文介绍了javascript是否有替换字符串的一部分而不创建新字符串的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
var str = "This is a string";
var thing = str.replace("string","thing");
console.log( str )
>> "This is a string"
console.log( thing )
>> "This is a thing"
除了replace之外,还有其他方法可以使用它来更改字符串而不给我新的字符串对象吗?
Is there another method I can use, besides replace, that will alter the string in place without giving me a new string object?
推荐答案
否,JavaScript中的字符串是不可变的.
No, strings in JavaScript are immutable.
这篇关于javascript是否有替换字符串的一部分而不创建新字符串的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文