Строка JavaScript содержит: Пошаговое руководство

| | | | | | |

–ü—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ JavaScript —Å–∏–º–≤–æ–ª –∏–ª–∏ —Ñ—Ä–∞–∑—É, –º–æ–∂–Ω–æ —Å –ø–æ–º–æ—â—å—é –º–µ—Ç–æ–¥–∞ includes (), indexOf () –∏–ª–∏ —Ä–µ–≥—É–ª—è—Ä–Ω–æ–≥–æ –≤—ã—Ä–∞–∂–µ–Ω–∏—è. includes () - —ç—Ç–æ –Ω–∞–∏–±–æ–ª–µ–µ —Ä–∞—Å–ø—Ä–æ—Å—Ç—Ä–∞–Ω–µ–Ω–Ω—ã–π –º–µ—Ç–æ–¥ –ø—Ä–æ–≤–µ—Ä–∫–∏ —Ç–æ–≥–æ, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –±—É–∫–≤—É –∏–ª–∏ –ø–æ—Å–ª–µ–¥–æ–≤–∞—Ç–µ–ª—å–Ω–æ—Å—Ç—å –±—É–∫–≤, –∏ –±—ã–ª —Ä–∞–∑—Ä–∞–±–æ—Ç–∞–Ω —Å–ø–µ—Ü–∏–∞–ª—å–Ω–æ –¥–ª—è —ç—Ç–æ–π —Ü–µ–ª–∏.

–ü—Ä–æ–≤–µ—Ä–∫–∞ —Ç–æ–≥–æ, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫—É, —è–≤–ª—è–µ—Ç—Å—è –æ–±—ã—á–Ω—ã–º –∑–∞–¥–∞—á–∞ –Ω–∞ –ª—é–±–æ–º —è–∑—ã–∫–µ –ø—Ä–æ–≥—Ä–∞–º–º–∏—Ä–æ–≤–∞–Ω–∏—è. –ù–∞–ø—Ä–∏–º–µ—Ä, –ø—Ä–µ–¥–ø–æ–ª–æ–∂–∏–º, —á—Ç–æ –≤—ã —Å–æ–∑–¥–∞–µ—Ç–µ –æ–Ω–ª–∞–π–Ω-–∏–≥—Ä—É. –í—ã –º–æ–∂–µ—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ –∏–º—è –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª—è –∑–∞–ø—Ä–µ—â–µ–Ω–Ω—É—é —Ñ—Ä–∞–∑—É, —á—Ç–æ–±—ã —É–±–µ–¥–∏—Ç—å—Å—è, —á—Ç–æ –≤—Å–µ –∏–º–µ–Ω–∞ –ø–æ–ª—å–∑–æ–≤–∞—Ç–µ–ª–µ–π –ø–æ–¥—Ö–æ–¥—è—Ç –¥–ª—è –≤–∞—à–µ–π –∏–≥—Ä—ã.

–°–æ–¥–µ—Ä–∂–∏—Ç —Å—Ç—Ä–æ–∫—É JavaScript

–°—É—â–µ—Å—Ç–≤—É–µ—Ç —Ç—Ä–∏ –º–µ—Ç–æ–¥–∞ –ø—Ä–æ–≤–µ—Ä–∫–∏ –Ω–∞–ª–∏—á–∏—è —Å—Ç—Ä–æ–∫–∏ JavaScript —Å–æ–¥–µ—Ä–∂–∏—Ç –¥—Ä—É–≥–æ–π —Å–∏–º–≤–æ–ª –∏–ª–∏ –ø–æ—Å–ª–µ–¥–æ–≤–∞—Ç–µ–ª—å–Ω–æ—Å—Ç—å —Å–∏–º–≤–æ–ª–æ–≤:

  • includes ().
  • indexOf ().
  • –†–µ–≥—É–ª—è—Ä–Ω—ã–µ –≤—ã—Ä–∞–∂–µ–Ω–∏—è (regex).

–í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –º—ã —Å–æ–±–∏—Ä–∞–µ–º—Å—è –æ–±—Å—É–¥–∏—Ç—å –º–µ—Ç–æ–¥—ã, –∫–æ—Ç–æ—Ä—ã–µ –≤—ã –º–æ–∂–µ—Ç–µ –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å, —á—Ç–æ–±—ã –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ JavaScript –¥—Ä—É–≥—É—é —Å—Ç—Ä–æ–∫—É, –∏—Å–ø–æ–ª—å–∑—É—è —ç—Ç–∏ —Ç—Ä–∏ –ø–æ–¥—Ö–æ–¥–∞.

String Contains JavaScript: includes () < / h3>

–ú–µ—Ç–æ–¥ JavaScript includes () , –ø—Ä–µ–¥—Å—Ç–∞–≤–ª–µ–Ω–Ω—ã–π –≤ ES6, –æ–ø—Ä–µ–¥–µ–ª—è–µ—Ç, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ —Å–∏–º–≤–æ–ª—ã, –∫–æ—Ç–æ—Ä—ã–µ –≤—ã –ø–µ—Ä–µ–¥–∞–ª–∏ –≤ –º–µ—Ç–æ–¥. –ï—Å–ª–∏ —Å—Ç—Ä–æ–∫–∞ —Å–æ–¥–µ—Ä–∂–∏—Ç –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–Ω—ã–µ —Å–∏–º–≤–æ–ª—ã, –º–µ—Ç–æ–¥ –≤–µ—Ä–Ω–µ—Ç " true. & Rdquo;

–ï—Å–ª–∏ —É–∫–∞–∑–∞–Ω–Ω–∞—è —Å—Ç—Ä–æ–∫–∞ –Ω–µ —Å–æ–¥–µ—Ä–∂–∏—Ç —Å–∏–º–≤–æ–ª–æ–≤, –∫–æ—Ç–æ—Ä—ã–µ –≤—ã –∏—â–µ—Ç–µ, includes () –≤–µ—Ä–Ω–µ—Ç " false "

–°–∏–Ω—Ç–∞–∫—Å–∏—Å –º–µ—Ç–æ–¥–∞ includes ():

–ó–Ω–∞—á–µ–Ω–∏–µ " —Å—Ç—Ä–æ–∫–∞ " –æ—Ç–Ω–æ—Å–∏—Ç—Å—è –∫ –ø–µ—Ä—Å–æ–Ω–∞–∂–∞–º, –ø–æ –∫–æ—Ç–æ—Ä—ã–º –º—ã –±—É–¥–µ–º –∏—Å–∫–∞—Ç—å. " word " –æ—Ç–Ω–æ—Å–∏—Ç—Å—è –∫ –ø–µ—Ä—Å–æ–Ω–∞–∂–∞–º, –∫–æ—Ç–æ—Ä—ã—Ö –º—ã –∏—â–µ–º.

81% —É—á–∞—Å—Ç–Ω–∏–∫–æ–≤ –∑–∞—è–≤–∏–ª–∏, —á—Ç–æ –æ–Ω–∏ –ø–æ—á—É–≤—Å—Ç–≤–æ–≤–∞–ª–∏ —Å–µ–±—è –±–æ–ª–µ–µ —É–≤–µ—Ä–µ–Ω–Ω—ã–º–∏ –≤ —Å–≤–æ–∏—Ö –ø–µ—Ä—Å–ø–µ–∫—Ç–∏–≤–∞—Ö —Ä–∞–±–æ—Ç—ã –≤ —Å—Ñ–µ—Ä–µ —Ç–µ—Ö–Ω–æ–ª–æ–≥–∏–π –ø–æ—Å–ª–µ –ø–æ—Å–µ—â–µ–Ω–∏—è —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è. –ü—Ä–æ–π–¥–∏—Ç–µ —É—á–µ–±–Ω—ã–π –∫—É—Ä—Å —Å–µ–≥–æ–¥–Ω—è.

–°—Ä–µ–¥–Ω–∏–π –≤—ã–ø—É—Å–∫–Ω–∏–∫ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –ø–æ—Ç—Ä–∞—Ç–∏–ª –º–µ–Ω–µ–µ —à–µ—Å—Ç–∏ –º–µ—Å—è—Ü–µ–≤ –Ω–∞ –ø–µ—Ä–µ—Ö–æ–¥–Ω—É—é –∫–∞—Ä—å–µ—Ä—É, –æ—Ç –Ω–∞—á–∞–ª–∞ —É—á–µ–±–Ω–æ–≥–æ –ª–∞–≥–µ—Ä—è –¥–æ –ø–æ–∏—Å–∫–∞ —Å–≤–æ–µ–π –ø–µ—Ä–≤–æ–π —Ä–∞–±–æ—Ç—ã.

–í–æ—Ç –ø—Ä–∏–º–µ—Ä —Ç–æ–≥–æ, –∫–∞–∫ —ç—Ç–æ —Å–¥–µ–ª–∞—Ç—å. –º–µ—Ç–æ–¥ includes () –≤ –¥–µ–π—Å—Ç–≤–∏–∏:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç: —Å–ª–æ–≤–æ Example –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –≤ —Å—Ç—Ä–æ–∫–µ.

–í –ø–µ—Ä–≤—ã—Ö –¥–≤—É—Ö —Å—Ç—Ä–æ–∫–∞—Ö –º—ã –æ–±—ä—è–≤–ª—è–µ–º –¥–≤–µ –ü–µ—Ä–µ–º–µ–Ω–Ω—ã–µ JavaScript . –ü–µ—Ä–≤–∞—è –ø–µ—Ä–µ–º–µ–Ω–Ω–∞—è - —ç—Ç–æ —Å—Ç—Ä–æ–∫–∞, –ø–æ –∫–æ—Ç–æ—Ä–æ–π –º—ã —Ö–æ—Ç–∏–º –∏—Å–∫–∞—Ç—å. –í—Ç–æ—Ä–∞—è - —ç—Ç–æ –ø–æ–¥—Å—Ç—Ä–æ–∫–∞, –∫–æ—Ç–æ—Ä—É—é –º—ã —Ö–æ—Ç–∏–º –Ω–∞–π—Ç–∏ –≤ –Ω–∞—à–µ–π –∏—Å—Ö–æ–¥–Ω–æ–π —Å—Ç—Ä–æ–∫–µ. –î—Ä—É–≥–∏–º–∏ —Å–ª–æ–≤–∞–º–∏, –º—ã –±—É–¥–µ–º –∏—Å–∫–∞—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ –ø–µ—Ä–≤–∞—è –ø–µ—Ä–µ–º–µ–Ω–Ω–∞—è —Å–æ–¥–µ—Ä–∂–∏–º–æ–µ –≤—Ç–æ—Ä–æ–π –ø–µ—Ä–µ–º–µ–Ω–Ω–æ–π.

–ó–∞—Ç–µ–º –º—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –æ–ø–µ—Ä–∞—Ç–æ—Ä if, —á—Ç–æ–±—ã –æ—Ü–µ–Ω–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ –ø–µ—Ä–µ–º–µ–Ω–Ω–∞—è " example " —Å–æ–¥–µ—Ä–∂–∏–º–æ–µ –ø–µ—Ä–µ–º–µ–Ω–Ω–æ–π " ourSubstring "

If " example & rdquo ; —Å–æ–¥–µ—Ä–∂–∏—Ç —Å–ª–æ–≤–æ " Example & rdquo ;, –Ω–∞—à–µ –≤—ã—Ä–∞–∂–µ–Ω–∏–µ –æ—Ü–µ–Ω–∏–≤–∞–µ—Ç—Å—è –∫–∞–∫ –∏—Å—Ç–∏–Ω–∞. –≠—Ç–æ –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è –∏–Ω—Å—Ç—Ä—É–∫—Ü–∏—è console.log () –≤ —Ç–µ–ª–µ –Ω–∞—à–µ–≥–æ –æ–ø–µ—Ä–∞—Ç–æ—Ä–∞ " if & rdquo ;. –í –ø—Ä–æ—Ç–∏–≤–Ω–æ–º —Å–ª—É—á–∞–µ –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è –Ω–∞—à–∞ –∏–Ω—Å—Ç—Ä—É–∫—Ü–∏—è " else " <. / p>

includes () —á—É–≤—Å—Ç–≤–∏—Ç–µ–ª–µ–Ω –∫ —Ä–µ–≥–∏—Å—Ç—Ä—É, –ø–æ—ç—Ç–æ–º—É, –µ—Å–ª–∏ –º—ã –∏–∑–º–µ–Ω–∏–º —Ä–µ–≥–∏—Å—Ç—Ä –Ω–∞—à–µ–π –ø–æ–¥—Å—Ç—Ä–æ–∫–∏, –±—É–¥–µ—Ç –≤–æ–∑–≤—Ä–∞—â–µ–Ω–æ " false & rdquo ;.

includes () –í—Ç–æ—Ä–æ–π –∞—Ä–≥—É–º–µ–Ω—Ç

–ú–µ—Ç–æ–¥ includes () –ø–æ–∑–≤–æ–ª—è–µ—Ç —É–∫–∞–∑–∞—Ç—å –≤—Ç–æ—Ä–æ–π –∞—Ä–≥—É–º–µ–Ω—Ç. –≠—Ç–æ—Ç –≤—Ç–æ—Ä–æ–π –∞—Ä–≥—É–º–µ–Ω—Ç –ø—Ä–µ–¥—Å—Ç–∞–≤–ª—è–µ—Ç —Å–æ–±–æ–π –Ω–æ–º–µ—Ä –∏–Ω–¥–µ–∫—Å–∞, —Å –∫–æ—Ç–æ—Ä–æ–≥–æ include () –¥–æ–ª–∂–µ–Ω –Ω–∞—á–∞—Ç—å –ø–æ–∏—Å–∫ –≤–∞—à–µ–π –ø–æ–¥—Å—Ç—Ä–æ–∫–∏. –ü–µ—Ä–≤—ã–π —Å–∏–º–≤–æ–ª –±—É–¥–µ—Ç –∏–º–µ—Ç—å –∏–Ω–¥–µ–∫—Å " 0 & rdquo ;, –≤—Ç–æ—Ä–æ–π " 1 & rdquo ; –∏ —Ç. –¥. –≠—Ç–æ –ø–æ—Ç–æ–º—É, —á—Ç–æ –ø–µ—Ä–µ—á–∏—Å–ª—è–µ—Ç –ø–æ–≤—Ç–æ—Ä–Ω–æ –ø—Ä–æ–∏–Ω–¥–µ–∫—Å–∏—Ä–æ–≤–∞–Ω–æ —Å –Ω—É–ª—è.

–î–∞–≤–∞–π—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏–º, —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤—É–µ—Ç –ª–∏ —Å–ª–æ–≤–æ " Example " –ø–æ—è–≤–ª—è–µ—Ç—Å—è –ø–æ—Å–ª–µ –ø–æ–∑–∏—Ü–∏–∏ –∏–Ω–¥–µ–∫—Å–∞ 7 –≤ –Ω–∞—à–µ–π —Å—Ç—Ä–æ–∫–µ:

–ú–µ—Ç–æ–¥ includes () –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –ø–æ–∑–∏—Ü–∏—é –∏–Ω–¥–µ–∫—Å–∞, —Å –∫–æ—Ç–æ—Ä–æ–π –Ω–∞—á–∏–Ω–∞–µ—Ç—Å—è –Ω–∞—à–∞ —Å—Ç—Ä–æ–∫–∞. –ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç " —Å–ª–æ–≤–∞ "–ø—Ä–∏–º–µ—Ä" –Ω–µ—Ç –≤ —Å—Ç—Ä–æ–∫–µ " –•–æ—Ç—è –Ω–∞—à–∞ —Å—Ç—Ä–æ–∫–∞ –≤–∫–ª—é—á–∞–µ—Ç —Å–ª–æ–≤–æ " –ü—Ä–∏–º–µ—Ä, " —Å–ª–æ–≤–æ –ø–æ—è–≤–ª—è–µ—Ç—Å—è –ø–µ—Ä–µ–¥ –∑–Ω–∞—á–µ–Ω–∏–µ–º –∏–Ω–¥–µ–∫—Å–∞ " 7, " –∫–æ—Ç–æ—Ä—ã–π —è–≤–ª—è–µ—Ç—Å—è –ø—Ä–æ–±–µ–ª–æ–º –º–µ–∂–¥—É " –ü—Ä–∏–º–µ—Ä–æ–º " –∏ " String! "

JavaScript –ü—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞: indexOf ()

–ú–µ—Ç–æ–¥ JavaScript indexOf () , –∫–∞–∫ –∏ includes (), –ø—Ä–æ–≤–µ—Ä—è–µ—Ç, –≤–∫–ª—é—á–∞–µ—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –¥—Ä—É–≥—É—é —Å—Ç—Ä–æ–∫—É. –û—Ç–ª–∏—á–∞–µ—Ç—Å—è –≤—ã–≤–æ–¥ —ç—Ç–∏—Ö –¥–≤—É—Ö —Ñ—É–Ω–∫—Ü–∏–π.

–ö–æ–≥–¥–∞ –º—ã –∏—Å–ø–æ–ª—å–∑—É–µ–º –º–µ—Ç–æ–¥ includes (), –º–µ—Ç–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –ª–æ–≥–∏—á–µ—Å–∫–æ–µ –∑–Ω–∞—á–µ–Ω–∏–µ: true –∏–ª–∏ false. indexOf () –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –Ω–∞—á–∞–ª—å–Ω–æ–µ –ø–æ–ª–æ–∂–µ–Ω–∏–µ –∏–Ω–¥–µ–∫—Å–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫–∏. –ò–ª–∏, –µ—Å–ª–∏ —Å—Ç—Ä–æ–∫–∞ –Ω–µ –≤–∫–ª—é—á–∞–µ—Ç –ø–æ–¥—Å—Ç—Ä–æ–∫—É, –º—ã " ll –ø–æ–ª—É—á–∏–º " -1. & Rdquo;

–î–∞–≤–∞–π—Ç–µ –ø–æ—Å–º–æ—Ç—Ä–∏–º –Ω–∞ —Å–∏–Ω—Ç–∞–∫—Å–∏—Å —ç—Ç–æ–≥–æ –º–µ—Ç–æ–¥–∞:

–ö–∞–∫ –∏ –≤ –Ω–∞—à–µ–º –ø—Ä–∏–º–µ—Ä–µ includes (), " string " –æ—Ç–Ω–æ—Å–∏—Ç—Å—è –∫ –∑–Ω–∞—á–µ–Ω–∏—é, –ø–æ –∫–æ—Ç–æ—Ä–æ–º—É –º—ã –∏—â–µ–º. " word " - —Ñ—Ä–∞–∑–∞ –∏–ª–∏ —Å–∏–º–≤–æ–ª, –∫–æ—Ç–æ—Ä—ã–µ –º—ã –∏—â–µ–º .

–í–æ—Ç –ø—Ä–∏–º–µ—Ä indexOf () –≤ JavaScript:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç: –°–ª–æ–≤–æ Example –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –≤ —Å—Ç—Ä–æ–∫–µ. –ú—ã –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–ª–∏ –æ–ø–µ—Ä–∞—Ç–æ—Ä " if ", –∫–∞–∫ –∏ –≤ –Ω–∞—à –ø–æ—Å–ª–µ–¥–Ω–∏–π –ø—Ä–∏–º–µ—Ä. –≠—Ç–æ—Ç –æ–ø–µ—Ä–∞—Ç–æ—Ä –æ—Ç–æ–±—Ä–∞–∂–∞–µ—Ç —á–∞—Å—Ç—å icular —Å–æ–æ–±—â–µ–Ω–∏–µ –Ω–∞ –∫–æ–Ω—Å–æ–ª—å –≤ –∑–∞–≤–∏—Å–∏–º–æ—Å—Ç–∏ –æ—Ç —Ç–æ–≥–æ, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ –Ω–∞—à–∞ —Å—Ç—Ä–æ–∫–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫—É.

–ú—ã –ø—Ä–æ–≤–µ—Ä—è–µ–º, –Ω–µ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç –ª–∏ –º–µ—Ç–æ–¥ indexOf () -1. –ï—Å–ª–∏ —ç—Ç–æ —Ç–∞–∫, " else " –í—ã–ø–∏—Å–∫–∞ –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è. -1 –æ–∑–Ω–∞—á–∞–µ—Ç, —á—Ç–æ –Ω–∞—à–∞ —Å—Ç—Ä–æ–∫–∞ –Ω–µ –º–æ–∂–µ—Ç –±—ã—Ç—å –Ω–∞–π–¥–µ–Ω–∞. –í –ø—Ä–æ—Ç–∏–≤–Ω–æ–º —Å–ª—É—á–∞–µ –∫–æ–¥ –≤ –Ω–∞—à–µ–º " if " –û–ø–µ—Ä–∞—Ç–æ—Ä –≤—ã–ø–æ–ª–Ω—è–µ—Ç—Å—è.

–ü—É—Å—Ç—å " s –∏—Å–ø–æ–ª—å–∑—É–µ—Ç indexOf () –¥–ª—è —Å—Ç—Ä–æ–∫–∏, –∫–æ—Ç–æ—Ä–∞—è –Ω–µ —Å–æ–¥–µ—Ä–∂–∏—Ç –ø–æ–¥—Å—Ç—Ä–æ–∫–∏:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç -1, –ø–æ—Ç–æ–º—É —á—Ç–æ –Ω–∞—à–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫–∞ –Ω–µ –º–æ–∂–µ—Ç –±—ã—Ç—å –Ω–∞–π–¥–µ–Ω–∞.

"–ö–∞—Ä—å–µ—Ä–Ω–∞—è –∫–∞—Ä–º–∞ –≤–æ—à–ª–∞ –≤ –º–æ—é –∂–∏–∑–Ω—å, –∫–æ–≥–¥–∞ —è –Ω—É–∂–¥–∞–ª—Å—è –≤ –Ω–µ–π –±–æ–ª—å—à–µ –≤—Å–µ–≥–æ –∏ –±—ã—Å—Ç—Ä–æ –ø–æ–º–æ–≥–ª–∏ –º–Ω–µ –ø—Ä–æ–π—Ç–∏ —É—á–µ–±–Ω—ã–π –∫—É—Ä—Å. –ß–µ—Ä–µ–∑ –¥–≤–∞ –º–µ—Å—è—Ü–∞ –ø–æ—Å–ª–µ –≤—ã–ø—É—Å–∫–∞ —è –Ω–∞—à–ª–∞ —Ä–∞–±–æ—Ç—É —Å–≤–æ–µ–π –º–µ—á—Ç—ã, –∫–æ—Ç–æ—Ä–∞—è —Å–æ–æ—Ç–≤–µ—Ç—Å—Ç–≤–æ–≤–∞–ª–∞ –º–æ–∏–º —Ü–µ–Ω–Ω–æ—Å—Ç—è–º –∏ —Ü–µ–ª—è–º –≤ –∂–∏–∑–Ω–∏! "

–í–µ–Ω–µ—Ä–∞, –∏–Ω–∂–µ–Ω–µ—Ä-–ø—Ä–æ–≥—Ä–∞–º–º–∏—Å—Ç –≤ Rockbot

indexOf (), –∫–∞–∫ –∏ –º–µ—Ç–æ–¥ includes (), —á—É–≤—Å—Ç–≤–∏—Ç–µ–ª–µ–Ω –∫ —Ä–µ–≥–∏—Å—Ç—Ä—É. –ï—Å–ª–∏ –º—ã —Ö–æ—Ç–∏–º, —á—Ç–æ–±—ã –Ω–∞—à –ø–æ–∏—Å–∫ –Ω–∞—á–∏–Ω–∞–ª—Å—è —Å –æ–ø—Ä–µ–¥–µ–ª–µ–Ω–Ω–æ–≥–æ –∑–Ω–∞—á–µ–Ω–∏—è –∏–Ω–¥–µ–∫—Å–∞, –º—ã –º–æ–∂–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –¥—Ä—É–≥–æ–π –∞—Ä–≥—É–º–µ–Ω—Ç:

–ü–æ—Å–∫–æ–ª—å–∫—É —Ç–æ—á–Ω–æ–µ —Å–æ–≤–ø–∞–¥–µ–Ω–∏–µ –Ω–µ –Ω–∞–π–¥–µ–Ω–æ, –Ω–∞—á–∏–Ω–∞—è —Å–æ –∑–Ω–∞—á–µ–Ω–∏—è –∏–Ω–¥–µ–∫—Å–∞ —Å–µ–º—å, –Ω–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç -1.

String —Å–æ–¥–µ—Ä–∂–∏—Ç JavaScript : Regex

–ú—ã —Ç–∞–∫–∂–µ –º–æ–∂–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å —Ä–µ–≥—É–ª—è—Ä–Ω—ã–µ –≤—ã—Ä–∞–∂–µ–Ω–∏—è JavaScript & mdash; –∏–ª–∏ —Ä–µ–≥—É–ª—è—Ä–Ω–æ–µ –≤—ã—Ä–∞–∂–µ–Ω–∏–µ & mdash;, —á—Ç–æ–±—ã –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫—É. –†–µ–≥—É–ª—è—Ä–Ω–æ–µ –≤—ã—Ä–∞–∂–µ–Ω–∏–µ –º–æ–∂–µ—Ç –±—ã—Ç—å –Ω–µ–≤–µ—Ä–æ—è—Ç–Ω–æ –ø–æ–ª–µ–∑–Ω—ã–º –±–ª–∞–≥–æ–¥–∞—Ä—è —Å–≤–æ–µ–π –≥–∏–±–∫–æ—Å—Ç–∏: —É –≤–∞—Å –µ—Å—Ç—å –ø–æ–ª–Ω—ã–π –∫–æ–Ω—Ç—Ä–æ–ª—å –Ω–∞–¥ —Ç–µ–º, —á—Ç–æ –≤—ã –∏—â–µ—Ç–µ –∏ –≥–¥–µ.

< / a>

–ú—ã –º–æ–∂–µ–º –∏—Å–ø–æ–ª—å–∑–æ–≤–∞—Ç—å –º–µ—Ç–æ–¥ RegExp.test (), —á—Ç–æ–±—ã –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫—É. –í–æ—Ç –ø—Ä–∏–º–µ—Ä:

–ù–∞—à –∫–æ–¥ –≤–æ–∑–≤—Ä–∞—â–∞–µ—Ç true. –≠—Ç–æ –ø–æ—Ç–æ–º—É, —á—Ç–æ " JavaScript " –Ω–∞—Ö–æ–¥–∏—Ç—Å—è –≤ –Ω–∞—à–µ–π " example " —Å—Ç—Ä–æ–∫–µ.

–†–µ–≥—É–ª—è—Ä–Ω–æ–µ –≤—ã—Ä–∞–∂–µ–Ω–∏–µ - –º–æ—â–Ω–æ–µ —Å—Ä–µ–¥—Å—Ç–≤–æ. –û–±—Ä–∞—Ç–Ω–æ–π —Å—Ç–æ—Ä–æ–Ω–æ–π —Ä–µ–≥—É–ª—è—Ä–Ω–æ–≥–æ –≤—ã—Ä–∞–∂–µ–Ω–∏—è —è–≤–ª—è–µ—Ç—Å—è —Ç–æ, —á—Ç–æ –æ–Ω–æ –º–æ–∂–µ—Ç –≤—ã–ø–æ–ª–Ω—è—Ç—å—Å—è –º–µ–¥–ª–µ–Ω–Ω–µ–µ –≤ –∑–∞–≤–∏—Å–∏–º–æ—Å—Ç–∏ –æ—Ç —Ç–æ–≥–æ, –∫–∞–∫–∏–µ –ø—Ä–∞–≤–∏–ª–∞ –≤—ã –∏—Å–ø–æ–ª—å–∑—É–µ—Ç–µ. –ß–µ–º –±–æ–ª—å—à–µ –æ–ø–µ—Ä–∞—Ç–æ—Ä–æ–≤ –≤—ã –¥–æ–±–∞–≤–ª—è–µ—Ç–µ –≤ —Å–≤–æ–π —Ä–µ–≥—É–ª—è—Ä–Ω—ã—Ö –≤—ã—Ä–∞–∂–µ–Ω–∏–π, —Ç–µ–º –¥–æ–ª—å—à–µ –±—É–¥–µ—Ç –≤–∞—à –ø–æ–∏—Å–∫.

–ï—Å–ª–∏ –≤—ã –≤—ã–ø–æ–ª–Ω—è–µ—Ç–µ –ø—Ä–æ—Å—Ç–æ–π –ø–æ–∏—Å–∫ –∏ –Ω–µ –Ω—É–∂–¥–∞–µ—Ç–µ—Å—å –≤ —Ä–∞—Å—à–∏—Ä–µ–Ω–Ω—ã—Ö —Å—Ç—Ä–æ–∫–æ–≤—ã—Ö —Ñ—É–Ω–∫—Ü–∏—è—Ö, –∏—Å–ø–æ–ª—å–∑–æ–≤–∞–Ω–∏–µ include () –∏–ª–∏ indexOf () –º–æ–∂–µ—Ç –±—ã—Ç—å –ª—É—á—à–∏–º –ø–æ–¥—Ö–æ–¥–æ–º. RegExp –ú–µ—Ç–æ–¥ .test () –Ω–µ —Ä–µ–∫–æ–º–µ–Ω–¥—É–µ—Ç—Å—è –¥–ª—è –Ω–æ–≤–∏—á–∫–æ–≤, –∫–æ—Ç–æ—Ä—ã–µ –µ—â–µ –Ω–µ –∑–Ω–∞–∫–æ–º—ã —Å Regex.

–ï—Å–ª–∏ –≤—ã —Ö–æ—Ç–∏—Ç–µ —É–∑–Ω–∞—Ç—å –±–æ–ª—å—à–µ –æ —Ä–µ–≥—É–ª—è—Ä–Ω–æ–º –≤—ã—Ä–∞–∂–µ–Ω–∏–∏ –∏ –ø—Ä–æ–≤–µ—Ä—å—Ç–µ —Å–≤–æ–µ —Ä–µ–≥—É–ª—è—Ä–Ω–æ–µ –≤—ã—Ä–∞–∂–µ–Ω–∏–µ, –æ–∑–Ω–∞–∫–æ–º—å—Ç–µ—Å—å —Å RegExr .

–ó–∞–∫–ª—é—á–µ–Ω–∏–µ < / h2>

–í —ç—Ç–æ–º —Ä—É–∫–æ–≤–æ–¥—Å—Ç–≤–µ –º—ã –æ–±—Å—É–¥–∏–ª–∏ –æ—Å–Ω–æ–≤—ã —Ä–∞–±–æ—Ç—ã —Å–æ —Å—Ç—Ä–æ–∫–∞–º–∏ –≤ JavaScript. –ü–æ—Å–ª–µ —ç—Ç–æ–≥–æ –º—ã –æ–±—Å—É–¥–∏–ª–∏ —Ç—Ä–∏ —Å–ø–æ—Å–æ–±–∞, –∫–æ—Ç–æ—Ä—ã–º–∏ –≤—ã –º–æ–∂–µ—Ç–µ –ø—Ä–æ–≤–µ—Ä–∏—Ç—å, —Å–æ–¥–µ—Ä–∂–∏—Ç –ª–∏ —Å—Ç—Ä–æ–∫–∞ –ø–æ–¥—Å—Ç—Ä–æ–∫—É –≤ JavaScript: —Å –ø–æ–º–æ—â—å—é include (), indexOf () –∏ regex.

–ú–µ—Ç–æ–¥ includes (), –≤–æ–∑–º–æ–∂–Ω–æ, —è–≤–ª—è–µ—Ç—Å—è –Ω–∞–∏–±–æ–ª–µ–µ —Ä–∞—Å–ø—Ä–æ—Å—Ç—Ä–∞–Ω–µ–Ω–Ω—ã–º. —Å–ø–æ—Å–æ–± –ø—Ä–æ–≤–µ—Ä–∫–∏ –Ω–∞–ª–∏—á–∏—è –≤ —Å—Ç—Ä–æ–∫–µ –ø–æ–¥—Å—Ç—Ä–æ–∫–∏. –≠—Ç–æ –ø–æ—Ç–æ–º—É, —á—Ç–æ –Ω–∞–∑–≤–∞–Ω–∏–µ –º–µ—Ç–æ–¥–∞ –±—É–∫–≤–∞–ª—å–Ω–æ–µ. –ü–æ–Ω—è—Ç–Ω–æ, —á—Ç–æ include () –ø–æ–∑–≤–æ–ª—è–µ—Ç –∏—Å–∫–∞—Ç—å —Å—Ç—Ä–æ–∫—É –≤–Ω—É—Ç—Ä–∏ –¥—Ä—É–≥–æ–π —Å—Ç—Ä–æ–∫–∏.

–•–æ—Ç–∏—Ç–µ —É–∑–Ω–∞—Ç—å –±–æ–ª—å—à–µ –æ JavaScript? –ú—ã –≤–∞—Å –ø—Ä–∏–∫—Ä—ã–ª–∏. –û–∑–Ω–∞–∫–æ–º—å—Ç–µ—Å—å —Å –Ω–∞—à–µ–π —Å—Ç–∞—Ç—å–µ–π "–ö–∞–∫ –∏–∑—É—á–∏—Ç—å JavaScript" , —á—Ç–æ–±—ã –ø–æ–ª—É—á–∏—Ç—å —Å–æ–≤–µ—Ç—ã —ç–∫—Å–ø–µ—Ä—Ç–æ–≤. –í—ã —Ç–∞–∫–∂–µ –Ω–∞–π–¥–µ—Ç–µ —Å–ø–∏—Å–æ–∫ –ª—É—á—à–∏—Ö —É—á–µ–±–Ω—ã—Ö —Ä–µ—Å—É—Ä—Å–æ–≤, –∫–æ—Ç–æ—Ä—ã–µ –ø–æ–º–æ–≥—É—Ç –≤–∞–º —Ä–∞—Å—à–∏—Ä–∏—Ç—å —Å–≤–æ–∏ –∑–Ω–∞–Ω–∏—è.