0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

初心者による初心者のためのspilt構文

0
Last updated at Posted at 2020-05-18
Page 1 of 2

はじめに

初めまして、私はJavaScriptの勉強を最近始めたばかりです。
そんな私でも出来たsplit構文について簡単に説明したいと思います!

そもそもsplit構文とは

  • split構文は文字列や数値が「,」(カンマ)や「 」(スペース)で区切られた配列を文字列を分割できます。

文だとイメージが掴みにくいと思うので例文で説明します!

Hello.javaScrip
   //まずスペースで区切られてる「dog koala wolf skunk」という配列を変数strに代入し        
   const str = 'dog koala wolf skunk'

   //次に変数strをsplitを使って分けた要素を変数wordsに代入します
   const words = str.split(' ');
    
   //こうするとwordsの中身が['dog', 'koala', 'wolf', 'skunk']になります
   //出力したい要素が先頭からn番目とするとwords[n]と入力します
   console.log(words[0]);
   

【結果】
dog

:warning:注意点

  • 要素の先頭から数えるので一番初めは0です!

最後に

  • split構文は覚えておけば応用にも使える便利な文法です!
  • 基礎の基礎しか書いてないですが参考にしていただけると嬉しいです。

参考リンク

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?