Regular Expressions - JavaScript | MDN - LIA

文章推薦指數: 80 %
投票人數:10人

Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. Skiptomaincontent Selectlanguage Skiptosearch Languages বাংলা(বাংলাদেশ) Deutsch Español Français 日本語 Português(do Brasil) Русский ไทย TiếngViệt 中文(简体) 正體中文(繁體) Addatranslation EditAdvanced Advanced History Printthispage MDN Webtechnologyfordevelopers JavaScript JavaScriptGuide RegularExpressions YourSearchResults RegularExpressions ShowSidebar InThisArticle CreatingaregularexpressionWritingaregularexpressionpatternUsingsimplepatternsUsingspecialcharactersUsingparenthesesWorkingwithregularexpressionsUsingparenthesizedsubstringmatchesAdvancedsearchingwithflagsExamplesChangingtheorderinaninputstringUsingspecialcharacterstoverifyinput «PreviousNext» Regularexpressionsarepatternsusedtomatchcharactercombinationsinstrings.InJavaScript,regularexpressionsarealsoobjects.Thesepatternsareusedwiththeexecand testmethodsofRegExp,andwiththe match,replace, search,and splitmethodsof String.ThischapterdescribesJavaScriptregularexpressions. Creatingaregularexpression Youconstructaregularexpressioninoneoftwoways: Usingaregularexpressionliteral,asfollows: varre=/ab+c/; Regularexpressionliteralsprovidecompilationoftheregularexpressionwhenthescriptisloaded.Whentheregularexpressionwillremainconstant,usethisforbetterperformance. OrcallingtheconstructorfunctionoftheRegExpobject,asfollows: varre=newRegExp("ab+c"); Usingtheconstructorfunctionprovidesruntimecompilationoftheregularexpression.Usetheconstructorfunctionwhenyouknowtheregularexpressionpatternwillbechanging,oryoudon'tknowthepatternandaregettingitfromanothersource,suchasuserinput. Writingaregularexpressionpattern Aregularexpressionpatterniscomposedofsimplecharacters,suchas/abc/,oracombinationofsimpleandspecialcharacters,suchas/ab*c/or/Chapter(\d+)\.\d*/.Thelastexampleincludesparentheseswhichareusedasamemorydevice.Thematchmadewiththispartofthepatternisrememberedforlateruse,asdescribedinUsingparenthesizedsubstringmatches. Usingsimplepatterns Simplepatternsareconstructedofcharactersforwhichyouwanttofindadirectmatch.Forexample,thepattern/abc/matchescharactercombinationsinstringsonlywhenexactlythecharacters'abc'occurtogetherandinthatorder.Suchamatchwouldsucceedinthestrings"Hi,doyouknowyourabc's?"and"Thelatestairplanedesignsevolvedfromslabcraft."Inbothcasesthematchiswiththesubstring'abc'.Thereisnomatchinthestring'Grabcrab'becausewhileitcontainsthesubstring'abc',itdoesnotcontaintheexactsubstring'abc'. Usingspecialcharacters Whenthesearchforamatchrequiressomethingmorethanadirectmatch,suchasfindingoneormoreb's,orfindingwhitespace,thepatternincludesspecialcharacters.Forexample,thepattern/ab*c/matchesanycharactercombinationinwhichasingle'a'isfollowedbyzeroormore'b's(*means0ormoreoccurrencesoftheprecedingitem)andthenimmediatelyfollowedby'c'.Inthestring"cbbabbbbcdebc,"thepatternmatchesthesubstring'abbbbc'. Thefollowingtableprovidesacompletelistanddescriptionofthespecialcharactersthatcanbeusedinregularexpressions. Specialcharactersinregularexpressions. Character Meaning \ Matchesaccordingtothefollowingrules: Abackslashthatprecedesanon-specialcharacterindicatesthatthenextcharacterisspecialandisnottobeinterpretedliterally.Forexample,a'b'withoutapreceding'\'generallymatcheslowercase'b'swherevertheyoccur.Buta'\b'byitselfdoesn'tmatchanycharacter;itformsthespecialwordboundarycharacter. Abackslashthatprecedesaspecialcharacterindicatesthatthenextcharacterisnotspecialandshouldbeinterpretedliterally.Forexample,thepattern/a*/reliesonthespecialcharacter'*'tomatch0ormorea's.Bycontrast,thepattern/a\*/removesthespecialnessofthe'*'toenablematcheswithstringslike'a*'. Donotforgettoescape\itselfwhileusingtheRegExp("pattern")notationbecause\isalsoanescapecharacterinstrings. ^ Matchesbeginningofinput.Ifthemultilineflagissettotrue,alsomatchesimmediatelyafteralinebreakcharacter. Forexample,/^A/doesnotmatchthe'A'in"anA",butdoesmatchthe'A'in"AnE". The'^'hasadifferentmeaningwhenitappearsasthefirstcharacterinacharactersetpattern.Seecomplementedcharactersetsfordetailsandanexample. $ Matchesendofinput.Ifthemultilineflagissettotrue,alsomatchesimmediatelybeforealinebreakcharacter. Forexample,/t$/doesnotmatchthe't'in"eater",butdoesmatchitin"eat". * Matchestheprecedingcharacter0ormoretimes.Equivalentto{0,}. Forexample,/bo*/matches'boooo'in"Aghostbooooed"and'b'in"Abirdwarbled",butnothingin"Agoatgrunted". + Matchestheprecedingcharacter1ormoretimes.Equivalentto{1,}. Forexample,/a+/matchesthe'a'in"candy"andallthea'sin"caaaaaaandy",butnothingin"cndy". ? Matchestheprecedingcharacter0or1time.Equivalentto{0,1}. Forexample,/e?le?/matchesthe'el'in"angel"andthe'le'in"angle"andalsothe'l'in"oslo". Ifusedimmediatelyafteranyofthequantifiers*,+,?,or{},makesthequantifiernon-greedy(matchingthefewestpossiblecharacters),asopposedtothedefault,whichisgreedy(matchingasmanycharactersaspossible).Forexample,applying/\d+/to"123abc"matches"123".Butapplying/\d+?/tothatsamestringmatchesonlythe"1". Alsousedinlookaheadassertions,asdescribedinthex(?=y)andx(?!y)entriesofthistable.   . (Thedecimalpoint)matchesanysinglecharacterexceptthenewlinecharacter. Forexample,/.n/matches'an'and'on'in"nay,anappleisonthetree",butnot'nay'. (x) Matches'x'andremembersthematch,asthefollowingexampleshows.Theparenthesesarecalledcapturingparentheses. The'(foo)'and'(bar)'inthepattern/(foo)(bar)\1\2/matchandrememberthefirsttwowordsinthestring"foobarfoobar".The\1and\2inthepatternmatchthestring'slasttwowords.Notethat\1,\2,\nareusedinthematchingpartoftheregex.Inthereplacementpartofaregexthesyntax$1,$2,$nmustbeused,e.g.:'barfoo'.replace(/(...)(...)/,'$2$1'). (?:x) Matches'x'butdoesnotrememberthematch.Theparenthesesarecallednon-capturingparentheses,andletyoudefinesubexpressionsforregularexpressionoperatorstoworkwith.Considerthesampleexpression/(?:foo){1,2}/.Iftheexpressionwas/foo{1,2}/,the{1,2}characterswouldapplyonlytothelast'o'in'foo'.Withthenon-capturingparentheses,the{1,2}appliestotheentireword'foo'. x(?=y) Matches'x'onlyif'x'isfollowedby'y'.Thisiscalledalookahead. Forexample,/Jack(?=Sprat)/matches'Jack'onlyifitisfollowedby'Sprat'./Jack(?=Sprat|Frost)/matches'Jack'onlyifitisfollowedby'Sprat'or'Frost'.However,neither'Sprat'nor'Frost'ispartofthematchresults. x(?!y) Matches'x'onlyif'x'isnotfollowedby'y'.Thisiscalledanegatedlookahead. Forexample,/\d+(?!\.)/matchesanumberonlyifitisnotfollowedbyadecimalpoint.Theregularexpression/\d+(?!\.)/.exec("3.141")matches'141'butnot'3.141'. x|y Matcheseither'x'or'y'. Forexample,/green|red/matches'green'in"greenapple"and'red'in"redapple." {n} Matchesexactlynoccurrencesoftheprecedingcharacter.Nmustbeapositiveinteger. Forexample,/a{2}/doesn'tmatchthe'a'in"candy,"butitdoesmatchallofthea'sin"caandy,"andthefirsttwoa'sin"caaandy." {n,m} Wherenandmarepositiveintegersandn<=m.Matchesatleastnandatmostmoccurrencesoftheprecedingcharacter.Whenmisomitted,it'streatedas∞. Forexample,/a{1,3}/matchesnothingin"cndy",the'a'in"candy,"thefirsttwoa'sin"caandy,"andthefirstthreea'sin"caaaaaaandy".Noticethatwhenmatching"caaaaaaandy",thematchis"aaa",eventhoughtheoriginalstringhadmorea'sinit. [xyz] Characterset.Thispatterntypematchesanyoneofthecharactersinthebrackets,includingescapesequences.Specialcharacterslikethedot(.)andasterisk(*)arenotspecialinsideacharacterset,sotheydon'tneedtobeescaped.Youcanspecifyarangeofcharactersbyusingahyphen,asthefollowingexamplesillustrate. Thepattern[a-d],whichperformsthesamematchas[abcd],matchesthe'b'in"brisket"andthe'c'in"city".Thepatterns/[a-z.]+/and/[\w.]+/matchtheentirestring"test.i.ng". [^xyz] Anegatedorcomplementedcharacterset.Thatis,itmatchesanythingthatisnotenclosedinthebrackets.Youcanspecifyarangeofcharactersbyusingahyphen.Everythingthatworksinthenormalcharactersetalsoworkshere. Forexample,[^abc]isthesameas[^a-c].Theyinitiallymatch'r'in"brisket"and'h'in"chop." [\b] Matchesabackspace(U+0008).Youneedtousesquarebracketsifyouwanttomatchaliteralbackspacecharacter.(Nottobeconfusedwith\b.) \b Matchesawordboundary.Awordboundarymatchesthepositionwhereawordcharacterisnotfollowedorpreceededbyanotherword-character.Notethatamatchedwordboundaryisnotincludedinthematch.Inotherwords,thelengthofamatchedwordboundaryiszero.(Nottobeconfusedwith[\b].) Examples: /\bm/matchesthe'm'in"moon"; /oo\b/doesnotmatchthe'oo'in"moon",because'oo'isfollowedby'n'whichisawordcharacter; /oon\b/matchesthe'oon'in"moon",because'oon'istheendofthestring,thusnotfollowedbyawordcharacter; /\w\b\w/willnevermatchanything,becauseawordcharactercanneverbefollowedbybothanon-wordandawordcharacter. Note: JavaScript'sregularexpressionenginedefinesaspecificsetofcharacterstobe"word"characters.Anycharacternotinthatsetisconsideredawordbreak.Thissetofcharactersisfairlylimited:itconsistssolelyofthe Romanalphabetinbothupper-andlower-case,decimaldigits,andtheunderscorecharacter.Accentedcharacters,suchas"é"or"ü"are,unfortunately,treatedaswordbreaks. \B Matchesanon-wordboundary.Thismatchesapositionwherethepreviousandnextcharacterareofthesametype:Eitherbothmustbewords,orbothmustbenon-words.Thebeginningandendofastringareconsiderednon-words. Forexample,/\B../matches'oo'in"noonday",and/y\B./matches'ye'in"possiblyyesterday." \cX WhereXisacharacterrangingfromAtoZ.Matchesacontrolcharacterinastring. Forexample,/\cM/matchescontrol-M(U+000D)inastring. \d Matchesadigitcharacter.Equivalentto[0-9]. Forexample,/\d/or/[0-9]/matches'2'in"B2isthesuitenumber." \D Matchesanynon-digitcharacter.Equivalentto[^0-9]. Forexample,/\D/or/[^0-9]/matches'B'in"B2isthesuitenumber." \f Matchesaformfeed(U+000C). \n Matchesalinefeed(U+000A). \r Matchesacarriagereturn(U+000D). \s Matchesasinglewhitespacecharacter,includingspace,tab,formfeed,linefeed.Equivalentto[\f\n\r\t\v​\u00a0\u1680​\u180e\u2000​-\u200a​\u2028\u2029\u202f\u205f​\u3000]. Forexample,/\s\w*/matches'bar'in"foobar." \S Matchesasinglecharacterotherthanwhitespace.Equivalentto[^\f\n\r\t\v​\u00a0\u1680​\u180e\u2000-\u200a​\u2028\u2029​\u202f\u205f​\u3000]. Forexample,/\S\w*/matches'foo'in"foobar." \t Matchesatab(U+0009). \v Matchesaverticaltab(U+000B). \w Matchesanyalphanumericcharacterincludingtheunderscore.Equivalentto[A-Za-z0-9_]. Forexample,/\w/matches'a'in"apple,"'5'in"$5.28,"and'3'in"3D." \W Matchesanynon-wordcharacter.Equivalentto[^A-Za-z0-9_]. Forexample,/\W/or/[^A-Za-z0-9_]/matches'%'in"50%." \n Wherenisapositiveinteger,abackreferencetothelastsubstringmatchingthenparentheticalintheregularexpression(countingleftparentheses). Forexample,/apple(,)\sorange\1/matches'apple,orange,'in"apple,orange,cherry,peach." \0 MatchesaNULL(U+0000)character.Donotfollowthiswithanotherdigit,because\0isanoctalescapesequence. \xhh Matchesthecharacterwiththecodehh(twohexadecimaldigits) \uhhhh Matchesthecharacterwiththecodehhhh(fourhexadecimaldigits). Escapinguserinputtobetreatedasaliteralstringwithinaregularexpressioncanbeaccomplishedbysimplereplacement: functionescapeRegExp(string){ returnstring.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"); } Usingparentheses Parenthesesaroundanypartoftheregularexpressionpatterncausethatpartofthematchedsubstringtoberemembered.Onceremembered,thesubstringcanberecalledforotheruse,asdescribedinUsingParenthesizedSubstringMatches. Forexample,thepattern/Chapter(\d+)\.\d*/illustratesadditionalescapedandspecialcharactersandindicatesthatpartofthepatternshouldberemembered.Itmatchespreciselythecharacters'Chapter'followedbyoneormorenumericcharacters(\dmeansanynumericcharacterand+means1ormoretimes),followedbyadecimalpoint(whichinitselfisaspecialcharacter;precedingthedecimalpointwith\meansthepatternmustlookfortheliteralcharacter'.'),followedbyanynumericcharacter0ormoretimes(\dmeansnumericcharacter,*means0ormoretimes).Inaddition,parenthesesareusedtorememberthefirstmatchednumericcharacters. Thispatternisfoundin"OpenChapter4.3,paragraph6"and'4'isremembered.Thepatternisnotfoundin"Chapter3and4",becausethatstringdoesnothaveaperiodafterthe'3'. Tomatchasubstringwithoutcausingthematchedparttoberemembered,withintheparenthesesprefacethepatternwith?:.Forexample,(?:\d+)matchesoneormorenumericcharactersbutdoesnotrememberthematchedcharacters. Workingwithregularexpressions RegularexpressionsareusedwiththeRegExpmethodstestandexecandwiththeStringmethodsmatch,replace,search,andsplit.ThesemethodsareexplainedindetailintheJavaScriptreference. Methodsthatuseregularexpressions Method Description exec ARegExpmethodthatexecutesasearchforamatchinastring.Itreturnsanarrayofinformation. test ARegExpmethodthattestsforamatchinastring.Itreturnstrueorfalse. match AStringmethodthatexecutesasearchforamatchinastring.Itreturnsanarrayofinformationornullonamismatch. search AStringmethodthattestsforamatchinastring.Itreturnstheindexofthematch,or-1ifthesearchfails. replace AStringmethodthatexecutesasearchforamatchinastring,andreplacesthematchedsubstringwithareplacementsubstring. split AStringmethodthatusesaregularexpressionorafixedstringtobreakastringintoanarrayofsubstrings. Whenyouwanttoknowwhetherapatternisfoundinastring,usethetestorsearchmethod;formoreinformation(butslowerexecution)usetheexecormatchmethods.Ifyouuseexecormatchandifthematchsucceeds,thesemethodsreturnanarrayandupdatepropertiesoftheassociatedregularexpressionobjectandalsoofthepredefinedregularexpressionobject,RegExp.Ifthematchfails,theexecmethodreturnsnull(whichcoercestofalse). Inthefollowingexample,thescriptusestheexecmethodtofindamatchinastring. varmyRe=/d(b+)d/g; varmyArray=myRe.exec("cdbbdbsbz"); Ifyoudonotneedtoaccessthepropertiesoftheregularexpression,analternativewayofcreatingmyArrayiswiththisscript: varmyArray=/d(b+)d/g.exec("cdbbdbsbz"); Ifyouwanttoconstructtheregularexpressionfromastring,yetanotheralternativeisthisscript: varmyRe=newRegExp("d(b+)d","g"); varmyArray=myRe.exec("cdbbdbsbz"); Withthesescripts,thematchsucceedsandreturnsthearrayandupdatesthepropertiesshowninthefollowingtable. Resultsofregularexpressionexecution. Object Propertyorindex Description Inthisexample myArray   Thematchedstringandallrememberedsubstrings. ["dbbd","bb"] index The0-basedindexofthematchintheinputstring. 1 input Theoriginalstring. "cdbbdbsbz" [0] Thelastmatchedcharacters. "dbbd" myRe lastIndex Theindexatwhichtostartthenextmatch.(Thispropertyissetonlyiftheregularexpressionusesthegoption,describedinAdvancedSearchingWithFlags.) 5 source Thetextofthepattern.Updatedatthetimethattheregularexpressioniscreated,notexecuted. "d(b+)d" Asshowninthesecondformofthisexample,youcanusearegularexpressioncreatedwithanobjectinitializerwithoutassigningittoavariable.Ifyoudo,however,everyoccurrenceisanewregularexpression.Forthisreason,ifyouusethisformwithoutassigningittoavariable,youcannotsubsequentlyaccessthepropertiesofthatregularexpression.Forexample,assumeyouhavethisscript: varmyRe=/d(b+)d/g; varmyArray=myRe.exec("cdbbdbsbz"); console.log("ThevalueoflastIndexis"+myRe.lastIndex); //"ThevalueoflastIndexis5" However,ifyouhavethisscript: varmyArray=/d(b+)d/g.exec("cdbbdbsbz"); console.log("ThevalueoflastIndexis"+/d(b+)d/g.lastIndex); //"ThevalueoflastIndexis0" Theoccurrencesof/d(b+)d/ginthetwostatementsaredifferentregularexpressionobjectsandhencehavedifferentvaluesfortheirlastIndexproperty.Ifyouneedtoaccessthepropertiesofaregularexpressioncreatedwithanobjectinitializer,youshouldfirstassignittoavariable. Usingparenthesizedsubstringmatches Includingparenthesesinaregularexpressionpatterncausesthecorrespondingsubmatchtoberemembered.Forexample,/a(b)c/matchesthecharacters'abc'andremembers'b'.Torecalltheseparenthesizedsubstringmatches,usetheArrayelements[1],...,[n]. Thenumberofpossibleparenthesizedsubstringsisunlimited.Thereturnedarrayholdsallthatwerefound.Thefollowingexamplesillustratehowtouseparenthesizedsubstringmatches. Thefollowingscriptusesthe replace()methodtoswitchthewordsinthestring.Forthereplacementtext,thescriptusesthe$1and$2inthereplacementtodenotethefirstandsecondparenthesizedsubstringmatches. varre=/(\w+)\s(\w+)/; varstr="JohnSmith"; varnewstr=str.replace(re,"$2,$1"); console.log(newstr); Thisprints"Smith,John". Advancedsearchingwithflags Regularexpressionshavefouroptionalflagsthatallowforglobalandcaseinsensitivesearching.Theseflagscanbeusedseparatelyortogetherinanyorder,andareincludedaspartoftheregularexpression. Regularexpressionflags Flag Description g Globalsearch. i Case-insensitivesearch. m Multi-linesearch. y Performa"sticky"searchthatmatchesstartingatthecurrentpositioninthetargetstring. Toincludeaflagwiththeregularexpression,usethissyntax: varre=/pattern/flags; or varre=newRegExp("pattern","flags"); Notethattheflagsareanintegralpartofaregularexpression.Theycannotbeaddedorremovedlater. Forexample,re=/\w+\s/gcreatesaregularexpressionthatlooksforoneormorecharactersfollowedbyaspace,anditlooksforthiscombinationthroughoutthestring. varre=/\w+\s/g; varstr="feefifofum"; varmyArray=str.match(re); console.log(myArray); Thisdisplays["fee","fi","fo"].Inthisexample,youcouldreplacetheline: varre=/\w+\s/g; with: varre=newRegExp("\\w+\\s","g"); andgetthesameresult. Themflagisusedtospecifythatamultilineinputstringshouldbetreatedasmultiplelines.Ifthemflagisused,^and$matchatthestartorendofanylinewithintheinputstringinsteadofthestartorendoftheentirestring. Examples Thefollowingexamplesshowsomeusesofregularexpressions. Changingtheorderinaninputstring Thefollowingexampleillustratestheformationofregularexpressionsandtheuseofstring.split()andstring.replace().Itcleansaroughlyformattedinputstringcontainingnames(firstnamefirst)separatedbyblanks,tabsandexactlyonesemicolon.Finally,itreversesthenameorder(lastnamefirst)andsortsthelist. //Thenamestringcontainsmultiplespacesandtabs, //andmayhavemultiplespacesbetweenfirstandlastnames. varnames="HarryTrump;FredBarney;HelenRigby;BillAbel;ChrisHand"; varoutput=["----------OriginalString\n",names+"\n"]; //Preparetworegularexpressionpatternsandarraystorage. //Splitthestringintoarrayelements. //pattern:possiblewhitespacethensemicolonthenpossiblewhitespace varpattern=/\s*;\s*/; //Breakthestringintopiecesseparatedbythepatternaboveand //storethepiecesinanarraycallednameList varnameList=names.split(pattern); //newpattern:oneormorecharactersthenspacesthencharacters. //Useparenthesesto"memorize"portionsofthepattern. //Thememorizedportionsarereferredtolater. pattern=/(\w+)\s+(\w+)/; //Newarrayforholdingnamesbeingprocessed. varbySurnameList=[]; //Displaythenamearrayandpopulatethenewarray //withcomma-separatednames,lastfirst. // //Thereplacemethodremovesanythingmatchingthepattern //andreplacesitwiththememorizedstring—secondmemorizedportion //followedbycommaspacefollowedbyfirstmemorizedportion. // //Thevariables$1and$2refertotheportions //memorizedwhilematchingthepattern. output.push("----------AfterSplitbyRegularExpression"); vari,len; for(i=0,len=nameList.length;i varre=/(?:\d{3}|\(\d{3}\))([-\/\.])\d{3}\1\d{4}/; functiontestInfo(phoneInput){ varOK=re.exec(phoneInput.value); if(!OK) window.alert(OK.input+"isn'taphonenumberwithareacode!"); else window.alert("Thanks,yourphonenumberis"+OK[0]); }

Enteryourphonenumber(withareacode)andthenclick"Check".
Theexpectedformatislike###-###-####.

Check «PreviousNext» DocumentTagsandContributors Tags:  Guide Reference Réference Référence RegularExpressions JavaScript Intermediate Contributorstothispage:lmorchard,webapphero,TTO,DanielRentz,Revolt,edymtt,jensen,boobl,daniel0mullins,JesseW,kscarfone,sfletche,trevorh,Penny,teddybeard,user01,Minat,mjhm,LoTD,Lamina-Paj,sonujaiswar,JanakaJR,BenoitL,schooley,jbnicolai,DarrinKoltow,btrager,morello,Sheppy,MartinRinehart,fscholz,jdphenix,Aqw,neilpquinn,bradleymeck,RustyDoorknobs,Kizer,xfq,FernandoBasso,arai,RobW,ironpingwin,SphinxKnight,dwcook,cerrahoglu.ali,ethertank,BYK,rodneyrehm,juicehonky,jscape,Mgjbot,berkerpeksag,bmenasha,zachleat,MajorSmall Lastupdatedby: xfq, May12,20155:18:47PM HideSidebar Seealso JavaScript Tutorials: JavaScriptGuide Introduction Grammarandtypes Controlflowanderrorhandling Loopsanditeration Functions Expressionsandoperators Numbersanddates Textformatting Regularexpressions Indexedcollections Keyedcollections Workingwithobjects Detailsoftheobjectmodel Iteratorsandgenerators Metaprogramming Introductory JavaScriptbasics JavaScripttechnologiesoverview IntroductiontoObjectOrientedJavaScript Intermediate Are-introductiontoJavaScript JavaScriptdatastructures Equalitycomparisonsandsameness Closures Advanced Inheritanceandtheprototypechain Strictmode JavaScripttypedarrays MemoryManagement ConcurrencymodelandEventLoop References: Built-inobjects Standardbuilt-inobjectsArrayArrayBufferBooleanDataViewDateErrorEvalErrorFloat32ArrayFloat64ArrayFunctionGeneratorGeneratorFunctionInfinityInt16ArrayInt32ArrayInt8ArrayInternalErrorIntlIntl.CollatorIntl.DateTimeFormatIntl.NumberFormatIteratorJSONMapMathNaNNumberObjectParallelArrayPromiseProxyRangeErrorReferenceErrorReflectRegExpSIMDSIMD.float32x4SIMD.float64x2SIMD.int16x8SIMD.int32x4SIMD.int8x16SetStopIterationStringSymbolSyntaxErrorTypeErrorTypedArrayURIErrorUint16ArrayUint32ArrayUint8ArrayUint8ClampedArrayWeakMapWeakSetdecodeURI()decodeURIComponent()encodeURI()encodeURIComponent()escape()eval()isFinite()isNaN()nullparseFloat()parseInt()undefinedunescape()uneval() Expressions&operators ExpressionsandoperatorsArithmeticoperatorsArraycomprehensionsAssignmentoperatorsBitwiseoperatorsCommaoperatorComparisonoperatorsConditional(ternary)OperatorDestructuringassignmentExpressionclosuresGeneratorcomprehensionsGroupingoperatorLegacygeneratorfunctionexpressionLogicalOperatorsObjectinitializerOperatorprecedencePropertyaccessorsSpreadoperatorclassexpressiondeleteoperatorfunctionexpressionfunction*expressioninoperatorinstanceofnewoperatorsuperthistypeofvoidoperatoryieldyield* Statements&declarations StatementsanddeclarationsLegacygeneratorfunctionblockbreakclassconstcontinuedebuggerdo...whileemptyexportforforeach...infor...infor...offunctionfunction*if...elseimportlabelletreturnswitchthrowtry...catchvarwhilewith Functions FunctionsArgumentsobjectArrowfunctionsDefaultparametersMethoddefinitionsRestparametersgettersetter Classes Classesconstructorextendsstatic Misc Lexicalgrammar JavaScriptdatastructures Enumerabilityandownershipofproperties Iterationprotocols Strictmode Transitioningtostrictmode Templatestrings Deprecatedfeatures NewinJavaScript NewinJavaScriptECMAScript5supportinMozillaECMAScript6supportinMozillaECMAScript7supportinMozillaFirefoxJavaScriptchangelogNewinJavaScript1.1NewinJavaScript1.2NewinJavaScript1.3NewinJavaScript1.4NewinJavaScript1.5NewinJavaScript1.6NewinJavaScript1.7NewinJavaScript1.8NewinJavaScript1.8.1NewinJavaScript1.8.5 Documentation: Usefullists Allpagesindex Methodsindex Propertiesindex Pagestagged"JavaScript" Contribute JavaScriptdocstatus TheMDNproject



請為這篇文章評分?