Home >Web Front-end >Front-end Q&A >How to remove trailing spaces in JavaScript

How to remove trailing spaces in JavaScript

藏色散人
藏色散人Original
2021-09-10 12:03:493149browse

How to remove trailing spaces in JavaScript: 1. Use the "osfipin.replace(/(^\s*)|(\s*$)/g, "");" method to remove leading and trailing spaces; 2. Use the "osfipin.replace(/(\s*$)/g, "");" method to remove the right space.

How to remove trailing spaces in JavaScript

The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer

How to remove trailing spaces in JavaScript?

JS simple method to remove leading and trailing spaces (native regular jquery)

var osfipin= '       http://www.xxx.com/osfipin/  ';
 
//去除首尾空格
osfipin.replace(/(^\s*)|(\s*$)/g, "");
 
//去除左边空格
osfipin.replace(/(^\s*)/g, "");
 
//去除右边空格
osfipin.replace(/(\s*$)/g, "");
 
//jquery 需提前引用jquery
$.trim(osfipin);
//另一种写法
jQuery.trim(osfipin);

Related introduction:

JavaScript (referred to as "JS") is a light-weighted JavaScript with function priority. magnitude, interpreted or just-in-time compiled programming language. Although it is famous as a scripting language for developing Web pages, it is also used in many non-browser environments. JavaScript is based on prototype programming, a multi-paradigm dynamic scripting language, and supports object-oriented, imperative, declarative, and functional programming paradigm.

JavaScript was first designed and implemented on the Netscape Navigator browser in 1995 by Brendan Eich of Netscape. Because Netscape was working with Sun, Netscape management wanted it to look like Java, hence the name JavaScript. But in fact its grammatical style is closer to Self and Scheme.

The standard for JavaScript is ECMAScript. As of 2012, all browsers fully support ECMAScript 5.1, and older browsers support at least the ECMAScript 3 standard. On June 17, 2015, ECMA International released the sixth edition of ECMAScript, which is officially called ECMAScript 2015, but is often called ECMAScript 6 or ES2015.

Recommended study: "javascript basic tutorial"

The above is the detailed content of How to remove trailing spaces in JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is js in javascriptNext article:What is js in javascript