Home  >  Article  >  Web Front-end  >  Instructions for using the path.extname method in node.js_node.js

Instructions for using the path.extname method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:28:121839browse

Method description:

Returns the path file extension. If the path ends with '.', '.' will be returned. If there is no extension and does not end with '.', a null value will be returned.

Grammar:

Copy code The code is as follows:

path.extname(p)

Since this method belongs to the path module, the path module needs to be introduced before use (var path= require(“path”) )

Receive parameters:

p path

Example:

Copy code The code is as follows:

path.extname('index.html')
// returns
'.html'
path.extname('index.')
// returns
'.'
path.extname('index')
// returns
''

Source code:

Copy code The code is as follows:

exports.extname = function(path) {
Return splitPath(path)[3];
};
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