array JavaScript
An Array in JavaScript is a sequenced list data structure used to store multiple values in a single variable.
Key attributes of arrays in JavaScript
Storage of multiple values: An array allows you to store different values (such as numbers, strings, objects, functions, or even other arrays) under a single variable name.
Index Access: Each member of the array is assigned a numerical index. Starting at 0 for the first member, 1 for the second, and so on. You can access or edit each member using this index.
Dynamic Size: Arrays in JavaScript can grow or shrink during program execution (no fixed size needed to be defined in the first place).
Mixed data types: Members within the same array, not necessarily the same data type (e.g. you can have numbers, strings, and booleans in the same array)
Array Creation
You can create arrays in many ways, but the most common is to use square brackets ([]):
JavaScript
/ / Create an empty array.
Let emptyArray = [];
/ / Create an array with members.
Let fruits = ["Apple," "Banana," "Cherry"];
/ / Create an array with mixed data types.
let mixedArray = [10, "Hello," true, {key: "value"}];
Access and editing members
Use the index within square brackets ([]) to access members:
JavaScript
Let colors = ["Red," "Green," "Blue"];
/ / Access to members
console.log (colors [0]); / / Result: "Red" (first member)
console.log (colors [2]); / / Result: "Blue"
/ / Membership amendments
Colors[1] = "Yellow";
console.log (colors); / / Results: ["Red," "Yellow," "Blue"]
/ / Monitoring the length of the array
console.log (colors.length); / / Results: 3
Arrays are a very basic and important tool in JavaScript programming for data set management.
ถ้าเจอคำว่า “array” แล้วอยากรู้ว่า array แปลว่าอะไรแบบสั้นๆ: โดยทั่วไปแปลได้ว่า “อาร์เรย์” หรือ “ชุดข้อมูล/รายการข้อมูล” คือการเอาค่าหลายๆ ค่า (เช่น ตัวเลขหรือข้อความ) มาวางเรียงกันเป็นลำดับ เพื่อให้จัดการได้ง่ายขึ้นในตัวแปรเดียว ใน JavaScript เวลาเราใช้ Array จะรู้สึกเหมือนมี “ลิสต์” เก็บของหลายชิ้นไว้ด้วยกัน เช่น เก็บตัวเลข 1–5 หรือเก็บชื่อผลไม้หลายชื่อ พอเป็นชุดข้อมูลแล้ว เราจะหยิบทีละชิ้นออกมาได้ด้วย “index” (ดัชนี) ที่เริ่มจาก 0 เสมอ ตัวอย่างที่เห็นบ่อยมากคือ - numbers = [1,2,3,4,5] (Array เก็บตัวเลข) - fruits = ["มะม่วง","มังคุด","ทุเรียน"] (Array เก็บข้อความ/สตริง) - mixedArray = [100, true, "javascript", {}] (เก็บข้อมูลหลายประเภทใน Array เดียว) สิ่งที่มือใหม่มักพลาดเวลาอ่านว่า “array แปลว่า” คือเข้าใจว่าเป็นแค่คำศัพท์ แต่จริงๆ มันเป็นแนวคิดสำคัญในการเขียนโปรแกรม: เราใช้ Array เพื่อจัดการข้อมูลหลายค่า เช่น รายการสินค้า คะแนนสอบ รายการงานที่ต้องทำ หรือข้อมูลที่ได้จาก API ทริคจำง่ายๆ ที่ผมใช้คือ “Array = กล่องยาวๆ ที่มีช่องเรียงกัน” - แต่ละช่องคือ element (สมาชิก) - เลขหน้าช่องคือ index (เริ่ม 0) ตัวอย่างการใช้งานที่ช่วยให้เห็นภาพ: 1) อยากหยิบ “สมาชิกตัวแรก” ออกมา fruits[0] จะได้ "มะม่วง" 2) อยากเปลี่ยนค่าช่องที่ 2 (index 1) fruits[1] = "เงาะ" ก็จะแทนที่ "มังคุด" 3) อยากรู้ว่ามีกี่ตัว fruits.length จะบอกจำนวนสมาชิกทั้งหมด สรุปอีกที: ถ้ามีคนถามว่า “array แปลว่าอะไร” ในบริบท JavaScript ให้ตอบได้เลยว่า “ชุด/รายการข้อมูลที่เรียงลำดับ เก็บหลายค่าในตัวแปรเดียว และเข้าถึงด้วย index” แค่นี้ก็ตรงเจตนาค้นหา และเอาไปต่อยอดเขียนโค้ดได้ทันที



































































































![A graphic titled "1. PREMIUM LEARNING [Student Discounts]" listing student offers for Babbel, Lingvist, CodeAcademy Pro, DataCamp, and Skillshare, alongside an "INTERACTIVE COURSES" graphic.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-maliva-v-ac5634-us/ocGEASNbgENoFQIfZebersDCxm2Qng4MAPHALL~tplv-sdweummd6v-shrinkf:640:0:q50.webp?lk3s=66c60501&source=seo_middle_feed_list&x-expires=1820469600&x-signature=dr5wmff63YMK%2F3ouDPAxUIJ%2FdKc%3D)
![A graphic titled "2. MENTAL HEALTH [Student Discounts]" listing student offers for Headspace and Spotify Premium, accompanied by a screenshot of the Headspace app interface.](https://p16-lemon8-sign-sg.tiktokcdn.com/tos-maliva-v-ac5634-us/ocz1mDF0eEDMNhADzFAQfmEnlRI2tVCBJAMTPC~tplv-sdweummd6v-shrinkf:640:0:q50.webp?lk3s=66c60501&source=seo_middle_feed_list&x-expires=1820469600&x-signature=xPKrgoLc5lhPIQJtJSRJMF7ZhN4%3D)










