Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: correct substring method in string article.md en#3891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
front42 wants to merge1 commit intojavascript-tutorial:master
base:master
Choose a base branch
Loading
fromfront42:patch-1
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions1-js/05-data-types/03-string/article.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -326,7 +326,7 @@ alert( "Wid*!*get*/!*".endsWith("get") ); // true, "Widget" ends with "get"

## Getting a substring

There are 3 methods in JavaScript to get a substring: `substring`, `substr` and `slice`.
There are 3 methods in JavaScript to get a substring: `slice`, `substring` and `substr`.

`str.slice(start [, end])`
: Returns the part of the string from `start` to (but not including) `end`.
Expand DownExpand Up@@ -356,9 +356,7 @@ There are 3 methods in JavaScript to get a substring: `substring`, `substr` and
```

`str.substring(start [, end])`
: Returns the part of the string *between* `start` and `end` (not including `end`).

This is almost the same as `slice`, but it allows `start` to be greater than `end` (in this case it simply swaps `start` and `end` values).
: Like `slice`, returns the part of the string from `start` to (but not including) `end`; however, it allows `start` to be greater than `end` (in this case it simply swaps `start` and `end` values).

For instance:

Expand DownExpand Up@@ -400,8 +398,8 @@ Let's recap these methods to avoid any confusion:

| method | selects... | negatives |
|--------|-----------|-----------|
| `slice(start, end)` | from `start` to`end` (not including `end`) | allows negatives |
| `substring(start, end)` |between `start`and `end` (not including `end`)| negative values mean `0` |
| `slice(start, end)` | from `start` to(butnot including) `end` | allows negatives |
| `substring(start, end)` |from `start`to (butnot including) `end`| negative values mean `0` |
| `substr(start, length)` | from `start` get `length` characters | allows negative `start` |

```smart header="Which one to choose?"
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp