We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
给出模板字符串
var str = 'my name is ${name}, and I am ${age}''
现在有一个对象
var obj = { name: 'zzy', age: 23 }
需要用obj中的对象替换模板字符串中的数字
function parseStr(str, obj) { Object.keys(obj).forEach(key => { str = str.replace(new RegExp(`\\$\{${key}\}`, 'g'), obj[key]) }) return str }
parseStr(str, obj) //my name is zzy, and I am 23
The text was updated successfully, but these errors were encountered:
No branches or pull requests
给出模板字符串
现在有一个对象
需要用obj中的对象替换模板字符串中的数字
The text was updated successfully, but these errors were encountered: