Home Web Front-end JS Tutorial JavaScript method to determine whether prefix and suffix are spaces_javascript skills

JavaScript method to determine whether prefix and suffix are spaces_javascript skills

May 16, 2016 pm 04:03 PM
javascript judgment prefix suffix space

The example in this article describes how JavaScript determines whether the prefix and suffix are spaces. Share it with everyone for your reference. The details are as follows:

// Js 判断后缀 
String.prototype.endsWith = function(suffix) { 
 return this.indexOf(suffix,this.length - suffix.length)!==-1; 
}; 
 
// Js 判断前缀
if (typeof String.prototype.startsWith != 'function') {
 // see below for better implementation!
 String.prototype.startsWith = function (str){
 return this.indexOf(str) == 0;
 };
} 
  
// Js 判空(含全部是空格)
String.prototype.IsNullEmptyOrSpace = function() 
{  
  if (this== null) return true; 
  return this.replace(/s/g, '').length == 0; 
};
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to open a file with .vsd suffix How to open a file with .vsd suffix Feb 18, 2024 pm 08:28 PM

How to open files with the suffix .vsd In daily computer use, we often encounter various types of file formats, and one of the common file formats is files with the suffix .vsd. So, how should we open this file with the suffix .vsd? First, we need to understand the meaning and purpose of .vsd files. VSD is the file format of Visio, a graphical drawing tool developed by Microsoft. VSD files are mainly used to create and edit various types of diagrams

How to quickly add a prefix in Excel? How to add prefixes to Excel tables in batches How to quickly add a prefix in Excel? How to add prefixes to Excel tables in batches Mar 14, 2024 am 09:16 AM

When editing Excel, you may need to add the same prefix to a column of data. If you add them one by one, it is a waste of time. Is there any way to add prefixes to Excel in batches? Of course there are, and here are some commonly used methods of adding prefixes. How to quickly add a prefix in Excel? 1. Cell formatting method 1. Select the cell range and press Ctrl1 at the same time to set the cell format. (Or right-click the mouse and select Format Cells) 2. Click [Customize], enter "Finance Department-@" in the [Type] option, and finally click [OK] to complete! 2. Plug-in method 1. Download and install the Excel plug-in Square Grid.​

WebSocket and JavaScript: key technologies for implementing real-time monitoring systems WebSocket and JavaScript: key technologies for implementing real-time monitoring systems Dec 17, 2023 pm 05:30 PM

WebSocket and JavaScript: Key technologies for realizing real-time monitoring systems Introduction: With the rapid development of Internet technology, real-time monitoring systems have been widely used in various fields. One of the key technologies to achieve real-time monitoring is the combination of WebSocket and JavaScript. This article will introduce the application of WebSocket and JavaScript in real-time monitoring systems, give code examples, and explain their implementation principles in detail. 1. WebSocket technology

The difference between full-width spaces and half-width spaces The difference between full-width spaces and half-width spaces Mar 25, 2024 pm 12:45 PM

The difference between full-width spaces and half-width spaces. When we use word processing software or edit text content, we sometimes encounter the concept of spaces. Space is a very basic element in typesetting and formatting text, but many people may not know the difference between full-width spaces and half-width spaces. In daily use, we may feel that full-width spaces and half-width spaces have different effects in different situations, but we may not be aware of the subtle differences. First of all, the difference between full-width spaces and half-width spaces is the width they occupy.

Simple JavaScript Tutorial: How to Get HTTP Status Code Simple JavaScript Tutorial: How to Get HTTP Status Code Jan 05, 2024 pm 06:08 PM

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

What is the magnet link prefix? What is the magnet link prefix? Feb 21, 2024 pm 08:45 PM

What is the magnet link prefix? Magnet links are a method for sharing files on the Internet. It has become the preferred way for many people to share and download resources. It allows users to easily get the files they need through a unified link. However, for those who are new to magnet links, some of the terms and concepts may be confusing. One of the common questions is, what is the magnet link prefix? Before answering this question, let us first understand the basic structure of magnet links. Magnet links consist of two parts: prefix and unique

How to use spaces correctly in Go How to use spaces correctly in Go Mar 29, 2024 pm 03:42 PM

Go language is a simple, efficient, and highly concurrency programming language. It is an open source language developed by Google. In the Go language, the use of spaces is very important, it can improve the readability and maintainability of the code. This article will introduce how to use spaces correctly in Go language and provide specific code examples. Why you need to use spaces correctly In the programming process, the use of spaces is very important for the readability and beauty of the code. Appropriate use of spaces can make code clearer and easier to read, thus reducing

How to determine whether a date is the previous day in Go language? How to determine whether a date is the previous day in Go language? Mar 24, 2024 am 10:09 AM

Question: How to determine whether the date is the previous day in Go language? In daily development, we often encounter situations where we need to determine whether the date is the previous day. In the Go language, we can implement this function through time calculation. The following will be combined with specific code examples to demonstrate how to determine whether the date is the previous day in Go language. First, we need to import the time package in the Go language. The code is as follows: import("time") Then, we define a function IsYest

See all articles