Home  >  Article  >  Web Front-end  >  js left, right, mid function_javascript skills

js left, right, mid function_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:03:492198browse

在JAVASCRIPT中LEFT,RIGHT,MID函数的等价函数 

function left(mainStr,lngLen) {
 if (lngLen>0) {return mainStr.substring(0,lngLen)}
 else{return null}
 } 

function right(mainStr,lngLen) {
// alert(mainStr.length)
 if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen return mainStr.substring(mainStr.length-lngLen,mainStr.length)}
 else{return null}
 }
function mid(mainStr,starnum,endnum){
 if (mainStr.length>=0){
 return mainStr.substr(starnum,endnum)
 }else{return null}
 //mainStr.length
 }

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