0
2

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.

【JavaScript】join基礎

Last updated at Posted at 2017-04-14

JavaScriptの勉強の備忘録として書き留めておきます。

#join
配列の各要素をまとめてひとつの文字列を作りたい時に使う。
第1引数はセパレータで、デフォルトは「,」になっている。

例えば下記のようにliを生成できます。(参考:オライリー「初めてのJavaScript」)

const team = ["Jin", "Ryuta", "Rysk"];
const html = '<ul><li>' + team.join('</li><li>') + '</li></ul>';
console.log(html); //<ul><li>Jin</li><li>Ryuta</li><li>Rysk</li></ul>

イタリア語の慣用句を使って、文字列をつなげるバージョンも試してみました。

const formula = "cafe, sigaretta, caca";
const array = ["cafe", "sigaretta", "caca"];
const arrayJoined = array.join(', ');
if (arrayJoined === formula) console.log("vai al bagno!"); //vai al bagno!
0
2
0

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?