\n JavaScript String Splitting: `substring()` vs. `split()`<\/h1>\n\n JavaScript offers two primary methods for dividing strings into substrings: `substring()` and `split()`. Each serves a distinct purpose.<\/p>\n\n
`substring()`<\/h2>\n The `substring()` method extracts a portion of a string based on starting and ending indices. It's ideal for retrieving a single substring from a known position within the string.<\/p>\n\n
Syntax:<\/strong> string.substring(startIndex, endIndex)<\/code><\/p>\n \n startIndex<\/code>: The index of the first character to include (0-based).<\/li>\n endIndex<\/code> (optional): The index *after* the last character to include. If omitted, the substring extends to the end of the string.<\/li>\n <\/ul>\n\n Example:<\/strong><\/p>\n \nconst str = \"Hello, world!\";\nconst sub = str.substring(7, 12); \/\/ Extracts \"world\"\nconsole.log(sub); \/\/ Output: \"world\"\n <\/pre>\n\n ??`indexof ()`? ???? ?? ?? ?? ??? ???? ?????.\n\n\n `split ()`\n `split ()`???? ??? ???? ???? ???? ??? ?? ??? ????. ??? ??? ?? ? ?? ??? ???? ???? ???? ? ????? (? : ??? ?? ? ?).\n\n ?? : <\/p>\n
\n : ???? ??? ? ???? ?? ?? ???. <\/h2>\n (?? ??) : ?? ? ??? ?? ??? ? \n \n\n ? : <\/p>\n
\n\n ?? ??? \n <\/strong>\n\n ? ???? ?????? string.split(separator, limit)\n <\/each><\/p>\n ??`substring ()`??? ??? ??? ???? ?? ?? ??? ??? ???? ? ?.\n ``split ()`? ??????. ??, ?? ?? ?? ??? ?? ???? ???? ???? ?? ???? ???? ? ?.\n \n\n \n\n\nseparator<\/code>\n<\/li> \n<\/ul><\/split><\/subs><\/split><\/use><\/p>"}
?
? ?????
JS ????
JavaScript?? ???? ?? ??? ???? ??
JavaScript?? ???? ?? ??? ???? ??
Feb 09, 2025 am 10:59 AM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript String Splitting: substring() vs. split()</title>
</head>
<body>
<h1>JavaScript String Splitting: `substring()` vs. `split()`</h1>
<p>JavaScript offers two primary methods for dividing strings into substrings: `substring()` and `split()`. Each serves a distinct purpose.</p>
<h2>`substring()`</h2>
<p>The `substring()` method extracts a portion of a string based on starting and ending indices. It's ideal for retrieving a single substring from a known position within the string.</p>
<p><strong>Syntax:</strong> <code>string.substring(startIndex, endIndex)</code></p>
<ul>
<li><code>startIndex</code>: The index of the first character to include (0-based).</li>
<li><code>endIndex</code> (optional): The index *after* the last character to include. If omitted, the substring extends to the end of the string.</li>
</ul>
<p><strong>Example:</strong></p>
<pre class="brush:php;toolbar:false"><code>
const str = "Hello, world!";
const sub = str.substring(7, 12); // Extracts "world"
console.log(sub); // Output: "world"
??`indexof ()`? ???? ?? ?? ?? ??? ???? ?????.
`split ()`
`split ()`???? ??? ???? ???? ???? ??? ?? ??? ????. ??? ??? ?? ? ?? ??? ???? ???? ???? ? ????? (? : ??? ?? ? ?).
?? :
: ???? ??? ? ???? ?? ?? ???.
(?? ??) : ?? ? ??? ?? ??? ?
? :
?? ???
? ???? ?????? string.split(separator, limit)
??`substring ()`??? ??? ??? ???? ?? ?? ??? ??? ???? ? ?.
``split ()`? ??????. ??, ?? ?? ?? ??? ?? ???? ???? ???? ?? ???? ???? ? ?.
? ??? JavaScript?? ???? ?? ??? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!
? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.
??? ??? JavaScript?? ??? ??????
Jul 04, 2025 am 12:42 AM
JavaScript? ??? ?? ????? ??? ?? ??? ??? ?? ?? ?? ????? ?? ???? ???? ?????. ??? ?? ???? ?? ??? ?? ??? ???? ???? ?? ?? ???? ???? ?????. ?? ??, ??? ? ?? ???? ??? (? : ??? null? ??) ?? ??? ????? ??????. ??? ??? ???? ??? ??? ????. closure?? ?? ??? ?? ??; ? ??? ??? ?? ?? ???? ?? ???? ????. V8 ??? ?? ???, ?? ??, ??/?? ???? ?? ??? ?? ??? ??? ????? ?? ??? ?? ??? ????. ?? ?? ???? ??? ??? ??? ??? ???? ????? ?? ?? ???? ?? ???????.
node.js?? HTTP ????? ???
Jul 13, 2025 am 02:18 AM
Node.js?? HTTP ??? ???? ? ?? ???? ??? ????. 1. ?? ????? ????? ??? ??? ? ?? ????? ?? ?? ? https.get () ??? ?? ??? ??? ? ?? ????? ?? ??? ?????. 2.axios? ??? ???? ? ?? ??????. ??? ??? ??? ??? ??? ??? ???/???, ?? JSON ??, ???? ?? ?????. ??? ?? ??? ????? ?? ????. 3. ?? ??? ??? ??? ??? ???? ???? ??? ??? ???? ?????.
JavaScript ??? ?? : ?? ? ??
Jul 13, 2025 am 02:43 AM
JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.
JavaScript Time Object, ??? Google Chrome? EACTEXE, ? ?? ? ???? ?????.
Jul 08, 2025 pm 02:27 PM
?????, JavaScript ???! ?? ? JavaScript ??? ?? ?? ?????! ?? ?? ??? ??? ??? ? ????. Deno?? Oracle? ?? ??, ??? JavaScript ?? ??? ????, Google Chrome ???? ? ??? ??? ???? ?????. ?????! Deno Oracle? "JavaScript"??? ????? Oracle? ?? ??? ??? ??????. Node.js? Deno? ??? ? Ryan Dahl? ??? ?????? ???? ????? JavaScript? ??? ???? Oracle? ????? ???? ?????.
REACT vs Angular vs Vue : ?? JS ??? ??? ?? ?????
Jul 05, 2025 am 02:24 AM
?? JavaScript ??? ??? ??? ?????? ?? ??? ?? ?? ??? ?? ???? ????. 1. ??? ???? ???? ?? ??? ?? ? ? ???? ??? ??? ?? ? ?? ????? ?????. 2. Angular? ?????? ??? ?? ???? ? ?? ?? ??? ??? ??? ???? ?????. 3. VUE? ???? ?? ??? ???? ?? ?? ??? ?????. ?? ?? ?? ??, ? ??, ???? ???? ? SSR? ???? ??? ??? ??? ???? ? ??? ?????. ???, ??? ??? ??? ????? ????. ??? ??? ??? ??? ?? ????.
JavaScript?? ?? ?? ??? (IIFE)? ?????
Jul 04, 2025 am 02:42 AM
iife (?? invokedfunctionexpression)? ?? ??? ???? ?? ????? ??? ???? ?? ??? ????? ?? ??? ? ?????. ??? ?? ?? ??? ???? ? ?? ??? ??? ?? (function () {/code/}) ();. ?? ???? ??? ?????. 1. ?? ??? ??? ?? ???? ?? ??? ??? ?????. 2. ?? ??? ??? ???? ?? ?? ??? ????. 3. ?? ?? ??? ????? ?? ???? ???????? ?? ? ??. ???? ?? ???? ?? ??? ES6 ??? ??? ??? ?? ? ??? ????? ??? ? ???? ???????.
?? ??? : JavaScript? ??, ?? ?? ? ?? ?????
Jul 08, 2025 am 02:40 AM
??? JavaScript?? ??? ??? ?????? ?? ???????. ?? ??, ?? ?? ? ??? ??? ?? ????? ????? ?????. 1. ?? ??? ??? ????? ???? ??. ()? ?? ??? ??? ?????. ?. ()? ?? ??? ?? ??? ??? ?? ? ? ????. 2. ?? ??? .catch ()? ???? ?? ??? ??? ?? ??? ??????, ??? ???? ???? ????? ??? ? ????. 3. Promise.all ()? ?? ????? (?? ?? ?? ? ??????? ??), Promise.Race () (? ?? ??? ?? ?) ? Promise.AllSettled () (?? ??? ???? ??)
?? API? ???? ??? ???? ??? ??????
Jul 08, 2025 am 02:43 AM
Cacheapi? ?????? ?? ???? ??? ???? ???, ?? ??? ??? ?? ???? ? ??? ?? ? ???? ??? ??????. 1. ???? ????, ??? ??, ?? ?? ?? ???? ???? ??? ? ????. 2. ??? ?? ?? ??? ?? ? ? ????. 3. ?? ?? ?? ?? ?? ??? ??? ?? ?????. 4. ??? ???? ?? ?? ???? ?? ?? ?? ?? ?? ???? ?? ?? ??? ??? ? ????. 5. ?? ???? ??, ??? ??? ? ??? ??, ?? ??? ? ?? ???? ???? ???? ? ?? ?????. 6.?? ??? ?? ?? ?? ??, ???? ?? ? HTTP ?? ????? ?????? ???????.
See all articles