数学講師2887710 views
高校生物551836 views
小学社会310533 views
ヒストリア290841 views
雑学1473656 views
中学社会668837 views
LaTeX962329 views
いろは3011793 views
中学英語811806 views
中学理科1630842 views

JavaScript Lecture

Help
Tools
NewsSpreadsheetCalendarBookkeepingMarkdown TablesLanguage Model NewsSlidesTier ListPen ToolIllustrationCrayonWatercolorPixel ArtASCII ArtPerspectiveEndless StairsGraphMind MapER DiagramFamily TreeMemeCurved TextImage EditorMosaicRetro FilterPencil SketchSwirl EffectLine ArtOCR/HighlighterMakeup EditorFaviconVideo TrimmerScrolling VideoVideo TitleColor PickerColor ExtractorBonfireFireworksCherry BlossomWater RippleWater SplashBreaking GlassGlass TextureFabric TextureWood GrainMarble TextureBrick Wall TextureMetal TextureWashi Paper TextureCardboard TextureCSS ButtonIcon MakerBar ChartGrouped Bar ChartStacked Bar ChartPie ChartLine ChartArea ChartStacked Area ChartScatter Plot3D Bar Chart3D Pie ChartBar Chart RaceBubble ChartPopulation PyramidPictogramEarningsCandlestick ChartInvestment RiskMortgage SimulatorCalculatorMatrix CalculatorFunction GraphPolynomial ExpansionVenn DiagramField VisualizerRubik's Cube Group TheoryTraveling SalesmanVoronoi and DelaunayFractalColumn ArithmeticDraw Math FiguresArithmetic AnimationArithmetic Word ProblemsCounting with Tree DiagramsCube NetsRolling DiceCross SectionsMotion PathMechanicsWavesElectromagnetic WavesCapacitorsLight and LensesThermodynamicsHow Semiconductors WorkMolecular StructuresAtomic OrbitalsElectrochemical CellsChemical EquilibriumCrystal LatticesBuffer pHOrganic Reaction MapPeriodic TableComplex IonsDNA Double HelixCell DivisionMembrane ChannelsNerve ImpulseMuscle ContractionHormones and HomeostasisRock ClassificationWeatherConstellationsSolar and Lunar Eclipses3D ModelingFloor PlanSeismic StructuresIntersection TurnMaglevCooking AnimationOrigamiLive Viewer CountGeoJSON MapRailway MapPopulation MapCrime MapLand Price MapSchool MapShrine and Castle MapHouse of Representatives MapWord MapSolitaireReversiHakoiri MusumeChessHamburgerRippleSlide Puzzle MakerNeon PinballNovel MakerJapanese Typing PracticePiano Score EditorMusic TheoryShogi StrategyPiano Rhythm Game

English

Surrogate pair regex is a good alternative to split('') when splitting a string by space

__The split('')__ returns a strange array when an original text contains emojis.
const word = 'AB😀C'

const items = word.split('')

console.log(items)
// ['A', 'B', '\uD83D', '\uDE00', 'C']

😀 is split to two code points. JavaScript uses UTF-16 and 😀 is expressed by UTF-16 surrogate pair. The below helps us to understand JS String object.

const word = 'AB😀C'

console.log(word.length)
// 5

An alternative to split function

Regular expression and match enable a string to be split as an emoji length is 1.

const word = 'AB😀C'

const array = word.match(/([\uD800-\uDBFF][\uDC00-\uDFFF])|./g)

console.log(array)
// ['A', 'B', '😀', 'C']

Surrogate pair is a pair of high and low surrogate. Both code point ranges are:

HighD800 - DBFF
LowDC00 - DFFF