Automatically translated.View original post

object.. JavaScript

# javascript # object

# Web Site Writing Basics

A JavaScript Object is a group of Property that stores data in the form of a pair of names and values. 📦

Object is considered the most important basic component of the JavaScript language because almost everything in JavaScript is an Object or works like an Object.

The main element of the Object.

Objects in JavaScript are collections of Property (properties), with each Property consisting of:

Name or Key: A unique string to identify and access data.

Value: It can be any data type (Data Types), such as strings, numbers, booleans, arrays, functions, or even other Objects.

Writing style:

JavaScript

Const person = {

/ / Key: Value

FirstName: "Alice," / / Property: String

LastName: "Wonder," / / Property: String

Age: 30, / / Property: Number

ISStudent: false, / / Property: Boolean

Hobbies: ["Reading," "Cooking"], / / Property: Array

/ / Property as a function is called "Method."

FULL Name: function () {

return this.firstName + "" + this.lastName;

}

};

Creating an Object

There are 3 main Object creation methods:

1. Object Literal (most popular)

It creates an Object using the {} sign.

JavaScript

Const car = {

Brand: "Toyota,"

Model: "Corolla,"

Year: 2022

};

2.Constructor Function (Traditional)

It is the use of a function to create a repeatedly structured Object using the new keyword.

JavaScript

Person (name, age) {

this.name = name;

This age = age;

}

Const Alice = new Person ("Alice," 30);

3.Class Syntax (ES6)

It is a more modern and easier to read format. Use class keywords to define the structure of the Object.

JavaScript

Dog class {

Constructor (name) {

this.name = name;

}

Bark () {

console.log ('${this.name} says Woof!');

}

}

Const buddy = new Dog ("Buddy");

Property access and change

You can access the value in Object in 2 ways:

1.Dot Notation (Most Popular)

Used when the property name is definitely known.

JavaScript

console.log (person.firstName); / / Result: "Alice"

Person. Age = 31; / / Change value

2. Bracket Notation

Use when the Property name is a variable or has special characters (e.g. spacing, dashes).

JavaScript

Const key = "lastName";

console.log (person [key]); / / Result: "Wonder"

person ["isStudent"] = true;

2025/10/23 Edited to

... Read moreหลายคนเริ่มเรียนภาษา JavaScript แล้วเจอคำว่า object บ่อยมาก แต่พอรันโค้ดแล้วดันขึ้นค่าแปลก ๆ อย่าง [object Object] เลยงงว่า “object คืออะไร” และอ่านค่ายังไงกันแน่ ตรงนี้เป็นสรุปเสริมจากที่อธิบายเรื่อง key:value, property และ method ไว้แล้ว เพื่อให้ใช้งานได้จริงมากขึ้น 1) Object คืออะไรในมุมใช้งานจริง ให้มอง Object เป็น “กล่องข้อมูลที่มีป้ายชื่อ” เราเก็บข้อมูลหลายชิ้นไว้ด้วยกัน และเรียกด้วย key เช่น person.firstName, person.age ซึ่งช่วยจัดระเบียบข้อมูลได้ดีกว่าการมีตัวแปรกระจัดกระจาย 2) ทำไมถึงเจอ [object Object] สาเหตุหลักคือเอา object ไปต่อสตริงหรือแสดงผลแบบ string ตรง ๆ เช่น const person = { firstName: "Alice" }; console.log("person = " + person); JavaScript จะพยายามแปลง object เป็นข้อความ ผลลัพธ์เลยเป็น [object Object] วิธีดูข้อมูลให้ถูก: - ดูทั้งก้อนแบบอ่านง่าย: console.log(person) - แปลงเป็น JSON: console.log(JSON.stringify(person)) - จัดให้อ่านง่ายขึ้น: console.log(JSON.stringify(person, null, 2)) ข้อควรจำ: JSON.stringify จะไม่เก็บ function (method) และบางค่าพิเศษอาจถูกละไว้ 3) เพิ่ม/ลบ/เช็ก property แบบที่ใช้บ่อย เพิ่มหรือแก้ค่า: person.age = 31; person["isStudent"] = true; ลบ property: delete person.hobbies; เช็กว่ามี key นี้ไหม: "age" in person // true/false หรือกันพลาดเวลาเรียกใช้: Object.hasOwn(person, "age") 4) Dot vs Bracket: เลือกให้ถูกสถานการณ์ - Dot notation: ใช้ง่ายและอ่านง่าย เมื่อรู้ชื่อ key แน่นอน เช่น person.lastName - Bracket notation: เหมาะเมื่อ key มาจากตัวแปร หรือมีอักขระพิเศษ/มีเว้นวรรค เช่น const key = "lastName"; person[key]; const settings = { "font-size": 14 }; settings["font-size"]; 5) this ใน method ทำงานยังไง (จุดที่มือใหม่พลาด) ใน method อย่าง fullName() ที่ใช้ this.firstName, this จะอ้างถึง object ที่เรียกใช้งาน ณ ตอนนั้น เช่น person.fullName() ถ้าไปแยกฟังก์ชันออกมาเรียกเดี่ยว ๆ อาจทำให้ this ไม่ชี้ไปที่ person แล้ว (โดยเฉพาะในบางบริบท) วิธีแก้คือเรียกผ่าน object หรือใช้ bind/arrow function ให้เหมาะกับงาน 6) สรุปจำง่าย - Object = collection ของ property (key:value) - Method = property ที่เป็น function - อยากหลีกเลี่ยง [object Object] ให้ใช้ console.log(obj) หรือ JSON.stringify(obj) - ใช้ dot เมื่อ key ตายตัว, ใช้ bracket เมื่อ key เป็นตัวแปร/มีอักขระพิเศษ ส่วนตัวพอจำ 4 ข้อนี้ได้ เวลาอ่านโค้ด JavaScript จะ “เห็นภาพ” โครงสร้างข้อมูลชัดขึ้น และต่อยอดไปเรื่อง array of objects, destructuring หรือการทำงานกับ API ได้ง่ายมาก

Related posts

I object to this game 🤣🤣😭😭
Onyx light

Onyx light

21.4K likes

A sketchbook page displays two pencil sketches of hands holding apples. Overlay text reads "HOW I DRAW HANDS HOLDING OBJECTS," serving as the title for a drawing tutorial on drawing hands holding objects.
A sketchbook shows two light pencil circles. Two real hands, one at the top right and one at the bottom right, hold red apples, demonstrating the initial step of drawing the object as a reference.
A sketchbook displays two circles with rough hand outlines sketched around them. Two real hands holding apples are shown, with green lines highlighting the main shapes of the hands for reference.
How I Draw Hands That Are Holding an Object
Using the object as a point of reference is just another way to get more accurate placements of the fingers and palm (you can use anything that’s in your reference photo and on your drawing). So for example: when I map out the fingers on the top hand, how far does the pointer finger extend to? Of
。 ₊°༺♡༻°₊ 。

。 ₊°༺♡༻°₊ 。

2848 likes

A young woman in a black and white outfit smiles, sitting in front of a blue container. The image is titled "Removing Objects USING CANVA," indicating a tutorial on photo editing.
A blurred background shows app icons, with the Canva app icon prominently displayed. A menu overlay offers options like "Open Canva," "Your Designs," and "Delete App," guiding the user to open the application.
The young woman from the first image is shown again. A bottom menu highlights the "Magic Studio" option, indicating the next step in the Canva object removal tutorial.
Object Removal Tutorial using Canva
1.) Upload your photo to Canva 2.) Select “edit image” 3.) Click “magic studio” 4.) Select “magic eraser” 5.) Select “click” 6.) Choose the object(s) you want to remove 7.) Select erase Sn: Magic Eraser is only available to Canva Pro, Canva Teams, Canva for Education, and Canva for Non
Oshi

Oshi

3 likes

Pick an Object...Get an Anime ⭐️
For this "Pick an Object" I wanted to lean a bit more on appearances than plot! 🎭✨️ Out of all these anime, my favorite is definitely the 🎴.... shhh no spoilers! 🤗 but it was one of my first anime so it holds a special place in my heart! Also it seems that you guys have been loving
"Dear Anime"

"Dear Anime"

2354 likes

Haunted Object Horror Book Recommendations
If you love horror where the real villain fits in your pocket, you’re in the right place. These haunted object stories turn everyday things—old dolls, antique mirrors, cursed tapes, strange heirlooms—into sources of pure dread. There’s something uniquely unsettling about horror that doesn’t need a
Izzy

Izzy

56 likes

Odd Object Curls 💪 & Some Tricep Action! ✊
#outdoorworkout #flexing #dadbod #armworkout #lemon8fit
Squeezy

Squeezy

19 likes

A man with tattoos and a cap sits at a desk, coding on a large monitor in a dimly lit room. Text overlays read 'SWIPE', 'Learning JavaScript?', and 'This is for YOU!', with a thinking emoji, promoting coding education.
A man with headphones and a cap codes at a desk with a large monitor displaying code. Text overlays read 'SWIPE', 'Break vs Continue', and 'In JS loops', with a thinking emoji, highlighting JavaScript loop concepts.
A man with headphones and a cap sits at a desk, coding on a large monitor in a bright room. Text overlays read 'Let's Discuss!' with a thinking emoji, inviting interaction about coding topics.
Coding W/ JavaScript?
As a software engineer w/ ADHD, understanding the difference between certain syntax keywords is critical, such as ‘continue’ and ‘break’ within JavaScript loops.💡 It’s almost like centering a <div> — it takes practice to feel confident in your abilities. 🛠️ When my mind gets stuck in a
Michael Burbank

Michael Burbank

13 likes

How I’d Learn JavaScript If I Were Starting Again
#javascript #coding #programming #tech #codingforbeginners
Aysha

Aysha

124 likes

Finished Object Friday
Happy I finally got to do a Finished Object Friday! I made this little scarf using my handspun yarn Fiona’s Swamp! I did a scalloped edge and I love the way it turned out! • #crochet #knit #yarn #fiberart #handmade
Mrs. Wheeler

Mrs. Wheeler

10 likes

A character sheet portrait of a smiling woman, a 52-year-old mom of seven, surrounded by elements reflecting her organized, resilient life. It highlights her journey balancing family, personal growth, and learning technology like Python, JavaScript, and SQL, with daily routines, goals, and affirmations for managing anxiety and ADHD.
🌹 From Python, JavaScript and SQL Books to Code Dreams: This Is Me
🌹 From Budget Books to Code Dreams: This Is Me This beautiful character-sheet portrait captures me being organized, resilient, and focused on growth. I am surrounded by planners, notebooks, coding references, roses, and inspirational reminders, I represent the perfect blend of determination and
mirandaperry05

mirandaperry05

1 like

If money were no object 😝
If only lol
Mailee Xiong

Mailee Xiong

19 likes

pick an object and i will tell you your 2026 reset
pick the object that feels like a reset button right now. the camera is nostalgia reset, the cup is soft-life reset, the planner is lock-in reset, and the earbuds are offline reset. i made the full test on skyquiz because sometimes your coping style is more honest than your aesthetic. search skyqui
SkyQuiz

SkyQuiz

8 likes

Found Object Mixed Media Nature Journal
Been thinking on making one for a mini lesson:) Was so much fun to do- watercolors, pencil, paint, twine, a box from the trash, and a few random things I’ve stuck in my pockets lately on nature walks. Zero planning ahead (it shows!) just a heap of scraps and a rough idea. So easy to do with your st
Creative Brains Grow Here

Creative Brains Grow Here

1 like

The "Action-Object" Labeling in Spanish
#spanishforbeginners #spanishforenglishspeakers #dailyspanishlessons #spanishlanguage #spanishforeveryday
MsD - Spanish for beginners

MsD - Spanish for beginners

5 likes

Two hands hold up shadow boxes filled with collected matchbooks, playing cards, and wooden letters, showcasing them in a living room setting. The text overlay reads, "MY APARTMENT'S ULTIMATE ICE BREAKER."
A close-up of a white shadow box filled with various matchbooks, wooden sticks, an Ace of Clubs playing card, and wooden letters spelling "RADIATE LOVE." The text overlay highlights "THESE MATCHBOOK SHADOW BOXES!"
A close-up of a white shadow box containing matchbooks, wooden sticks, an Ace of Spades playing card, and wooden letters spelling "EXPLORATION." The text overlay describes them as unique conversation starters made on a date night.
object in my apt starts the most conversations🤭
hi besties!!! i hope you're doing AMAZING! one things i looooove to do is host/have guests over, but one things i need to get better at is: starting conversations. but these shadow boxes are always an ice breaker and a great conversation starter. people are always interested in h
freckledlaur

freckledlaur

1652 likes

Finished object alert!
I double knit this headband by hand using a cream tweed yarn and a forest green yarn. What other colors should I use next? What colors would you like to pair with your fall and winter outfits? thank you, my lovely friends! #knitting #handknit #falloutfitinspo #headband #knittersoflemon8
AlliMarieMakes

AlliMarieMakes

10 likes

Babies before they have object permanence…
Before babies have object permanence… Playing peekaboo and all of a sudden they get startled when you “boo” like they forgot you were there. Or going upstairs and their eyes get wide like they didn’t realize there was a whole other part of the house beyond those stairs Or falling asleep
Oh-FourtheLove

Oh-FourtheLove

127 likes

#ObjectManipulationMonday
#objectmanipulation Note🚨: THIS KNIFE IS A TRAINER ONLY❗ BALISONG FLIPPING WITH A LIVE BLADE IS DANGEROUS‼️ #balisong #flipping #shotononeplus #FyreNationCrew
C3

C3

2 likes

flying object
When I asked my child, "Do you see something flying in the sky?" he couldn't see it. I took a video and showed it to him, but he still couldn't see it. #ufo #UFOキャッチャー #alien #muggle
Sean.QQ

Sean.QQ

3 likes

If money were no object 😝
Money mindset 💸 | Wealth & investing 🚀 | Budget tips & motivation 🌟 #Wealth - #MoneyGoals - #FinancialFreedom - #RichLife - #MoneyTalks - #HustleHard - #PassiveIncome - #FinancialLiteracy - #MoneyMindset - #WealthBuilding WealthWise.univer.se
Wealth Wise 3333

Wealth Wise 3333

3 likes

#ObjectManipulationMonday
#ObjectManipulationMonday #objectmanipulation #WeOnFyreCypher 38 🎥: @Poggy Doggy #boom #theroots
C3

C3

1 like

A title slide on a blue sky background reads 'Making object show ocs based on disorders' and explains that viewers can claim OCs and modify them.
A hand-drawn apple character named 'Apple' is depicted with red stripes, a smiling face, and text indicating it is 'Autistic lvl 1', '22 mentally 14 or 6', and 'bit chubby'.
The apple character holds a box of sunglasses, illustrating the autistic trait 'Collects glasses'. A black shape is partially visible on the right.
Making object show ocs based on disorders 1
Erm. Someone who exists.

Erm. Someone who exists.

5 likes

A collage of colorful object show doodles featuring various characters like a puzzle piece, a black blob, a pink marker, a yellow star, and a white card. Speech bubbles show humorous dialogue and interactions between the characters.
A cropped doodle showing a red and yellow puzzle piece character distressed about missing coffee. Below, a white card character stands near a spilled coffee cup on a table, with a gray pebble character warning, "Card, be careful that's Puzzle's coffee."
A comprehensive collage of object show doodles, including characters like a puzzle piece, a black blob, a pink marker, and a white card, engaged in various humorous interactions and conversations.
Object show doodles!
Here are some doodles for PTTP, my object show! I’m currently working on a small Christmas project so I probably won’t have any new animations for a bit:P . . . #objectshowcommunity #osc #objectshow #objectshowoc #objectshowfyp
PuzzleNoon

PuzzleNoon

22 likes

I OBJECT!
#shorts #funnyvideos #court #squirrel #viral
Stop_it_Daddy

Stop_it_Daddy

1 like

This Object Has a Second Identity
This Object Has a Second Identity
FurniFlex 3D

FurniFlex 3D

2 likes

The object that starts the most conversations
I absolutely love these vintage fairy lights and they always get compliments when we have guests over or when I share them on social media, they truly are so beautiful (even more in person). I keep one on my coffee table and one on the back of the toilet in both bathrooms! I found my vintage fairy
BrandyJackson

BrandyJackson

167 likes

what do yall think of object hell?
*super cool caption* #bfdi #bfdia #objectshowcommity #objecthellbfdia #fyp
Coyote_5850🐾

Coyote_5850🐾

3 likes

A blue cartoon character resembling the number four, with wide eyes and a smiling mouth, is shown with the text "OBJECT SHOW OFFICIAL ART!!" overlaid.
A hand-drawn sketch on lined paper depicts a round, smiling character with large eyes and small limbs, waving its hand.
A hand-drawn sketch on lined paper shows a cat-like character with a relaxed expression, small ears, and short limbs.
OBJECT SHOW OFFICIAL ART!!
#objectshowcommity #objectshows
Sourteeth

Sourteeth

9 likes

Turning a little yarn into a new object.
Why do I work on Christmas items so early in the year? Because I'm slow! 😂 This stocking for my daughter took me months, and I still have two more to do before December. #lemon8diarychallenge #crochet #christmas #crochetinspiration #workofart
Hanna 💜

Hanna 💜

61 likes

Making object show ocs based off of disorders 2
Erm. Someone who exists.

Erm. Someone who exists.

2 likes

Mystery Object Spotted In The Sky Over Acapulco
A 4K HD photograph reportedly shows an unidentified flying object hovering over the skyline of Acapulco in the state of Guerrero. Witnesses say the object appeared stationary for several minutes before slowly moving away. The image quickly started circulating online with many people debating wha
madebytwen

madebytwen

220 likes

An object from Galactic family
Does this object resonate, the light language, the symbolism, the energy ? If so you are a Flamekeeper and carry a codex for the New Earth. #flamekeeper #butterfly #lightworker
TheButterflySanctuary33🌈🦋😇

TheButterflySanctuary33🌈🦋😇

5 likes

See more