Home > Web Front-end > JS Tutorial > body text

What is the difference between substr and substring in javascript

王林
Release: 2020-11-30 11:41:10
Original
7575 people have browsed it

The difference between substr and substring in javascript is: substr extracts a string of specified length starting from the starting index number; substring extracts the characters between two specified index numbers in the string.

What is the difference between substr and substring in javascript

Difference introduction:

(Video learning sharing: javascript video tutorial)

substr( start,length) is to extract a string of specified length starting from the starting index number;

substring(start,stop) is to extract the characters between two specified index numbers in the string; (same as in Java ), mathematically equivalent to extracting characters between [start,stop).

Example:

var letters = "abcdefg";
console.log(letters.substr(1,3))//结果为bcd
console.log(letters.substring(1,3));//结果为bc
Copy after login

Related recommendations:js tutorial

The above is the detailed content of What is the difference between substr and substring in javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!