JS字符串使用占位符轻松实现拼接(来自react源码)

react

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width,height=device-height">

<title>JS字符串使用占位符轻松实现拼接(来自react源码)</title>

<style>

</style>

</head>

<body>

<script>

let args = ['xu', '徐']

let s = '%s , %s'

let argIndex = 0

let newString = '%s , %s'.replace(/%s/g, () => args[argIndex++])

console.log(s) //%s , %s

console.log(newString) //xu , 徐

</script>

</body>

</html>

以上是 JS字符串使用占位符轻松实现拼接(来自react源码) 的全部内容, 来源链接: utcz.com/z/383456.html

回到顶部