JavaScript : substring vs. substr

814 단어 JavaScript

String.substring(start-index,stop-index)
  •  start-index: (Required - Numeric Value) - where to start the extraction
  •  stop-index : (Optional - Numeric Value) - where to stop the extraction
  •     var str = "Hello World";
        document.write(str.substring(4,8));
    

     
     
     
    String.substr(start-index,length)
  •  start-index: (Required - Numeric Value) - where to start the extraction
  •  length : (Optional - Numeric Value) - how many characters to extract
  •     var str = "Hello World";
        document.write(str.substr(4,4));
    

      
     
    Since JavaScript substr() is not cross-browser, I never use it.
     
     
    –end–

    좋은 웹페이지 즐겨찾기