Skip to Content
Head First JavaScriptプログラミング、第2版
book

Head First JavaScriptプログラミング、第2版

by Eric Freeman, Elisabeth Robson
March 2025
Intermediate to advanced
662 pages
13h 28m
Japanese
O'Reilly Media, Inc.
Content preview from Head First JavaScriptプログラミング、第2版

第4章. データに秩序を持たせる配列

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

Image

JavaScriptには、数字、文字列、ブール以上のものがある。これまでは、文字列、数値、そして "Fido "や "23"、"true "といったブールといったプリミティブを使ってJavaScriptのコードを書いてきた。プリミティブ型を使って多くのことができるが、ある時点でより多くのデータを扱わなければならなくなる。例えば、ショッピング・カート内の全商品、プレイリスト内の全曲、星のセットとその見かけの等級、商品カタログ全体などだ。そのためには、もう少し大きな力が必要だ。この章では、データを配列に入れる方法、配列にデータを渡す方法、配列の演算子について説明する。この後の章では、データを構造化する他の方法をいくつか見ていくが、まずは配列から始めよう。

Bubbles-R-Usの力になれるか?

Bubbles-R-Us社を紹介しよう。彼らのたゆまぬ研究により、どこにでもあるバブルワンドやマシンが最高の泡を吹けるのだ。今日、彼らは新しいバブル溶液のいくつかのバリエーションの「バブル係数」をテストしている。これがそのデータだ:

Image
Image

もちろん、これらのデータをすべてJavaScriptに取り込み、分析に役立つコードを書けるようにしたい。しかし、それはたくさんの値だ。これらの値を処理するために、どのようにコードを構築するつもりなのか?

JavaScriptで複数の値を表現する方法

JavaScriptで文字列、数値、ブール値のような単一の値を表現する方法は知っているだろうが、10個のバブル解答のすべてのバブル係数得点のような複数の値を表現するにはどうすればいいのだろうか?そのためには、JavaScriptの配列を使う。配列とは、多くの値を保持できるJavaScriptの型である。以下は、すべてのバブル係数スコアを保持するJavaScript配列である:

Image

すべての値を全体として扱うこともできるし、必要なときに個々のスコアにアクセスすることもできる。これをチェックしよう:

Image
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

技術リーダーシップのための14のヒント

技術リーダーシップのための14のヒント

島田 浩二
カオスエンジニアリング ―回復力のあるシステムの実践

カオスエンジニアリング ―回復力のあるシステムの実践

Casey Rosenthal, Nora Jones, 堀 明子, 松浦 隼人
Tidy First? ―個人で実践する経験主義的ソフトウェア設計

Tidy First? ―個人で実践する経験主義的ソフトウェア設計

Kent Beck, 吉羽 龍太郎, 永瀬 美穂, 細澤 あゆみ

Publisher Resources

ISBN: 9798341633186