Sunday, January 19, 2025
HomeProgrammingArray inside a JavaScript Object?

Array inside a JavaScript Object?

Yes, you can have an array inside a JavaScript object. An object in JavaScript can store different data types as its properties, including arrays. Here’s an example:

const person = {
name: “John”,
age: 30,
hobbies: [“reading”, “swimming”, “gaming”]
};

See also  Understanding Composite Key in DBMS

console.log(person.hobbies); // Output: [“reading”, “swimming”, “gaming”]

In this example, the person object has a property hobbies, which is an array. You can access the array like any other object property and manipulate it as needed.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x