---
title: "js去空格之重写trim方法"
author: "lcb530"
date: "2010-06-18T15:52:28Z"
tags: []
categories: ["Web前端"]
slug: "js-trim"
draft: false
lastmod: "2010-06-18T15:52:28Z"
id: 694010
url: "https://lcb530.iteye.com/blog/694010"
---

重写后的trim方法可以去&nbsp;与' '空格

```java
String.prototype.trim = function() {
     return this.replace(/^[\s\u3000\xa0]+|[\s\u3000\xa0]+$/g,"");  
}
```