replace,将指定字符串当中的字符替换为空
一个变量
<script type="text/javascript"> var str = ‘hello_100x100‘ console.log(str) 打印出hello_100x100 var str2 = str.replace(‘_100x100‘, ‘‘) console.log(str2) 打印出hello </script>
一个数组
<script type="text/javascript"> var array = [ ‘wo_100x100‘, ‘nc_100x100‘, ‘woc_100x100‘, ] var arrlist = array.forEach(item => { // document.write(item + ‘<br>‘) document.write(item.replace(‘_100x100‘, ‘‘) + ‘<br>‘)
打印出
wo
nc
woc }) </script>
原文:https://www.cnblogs.com/black-eyes/p/14552066.html