var.replace is not a function

前端 未结 10 2286
悲&欢浪女
悲&欢浪女 2020-12-04 13:50

I\'m using the below code to try to trim the string in Javascript but am getting the error mentioned in the title:

function trim(str) {
    return str.replac         


        
10条回答
  •  萌比男神i
    2020-12-04 14:19

    probable issues:

    • variable is NUMBER (instead of string);
      num=35; num.replace(3,'three'); =====> ERROR
      num=35; num.toString().replace(3,'three'); =====> CORRECT !!!!!!
      num='35'; num.replace(3,'three'); =====> CORRECT !!!!!!
    • variable is object (instead of string);
    • variable is not defined;

提交回复
热议问题