Preparing your workspace
Objects store related values using properties, while arrays store ordered collections that can be processed by index and array methods.
Objects are useful when several values belong to one entity. For example, a student object can contain a name, role, score, and course. Arrays are useful for collections such as a list of students or lessons. Objects use property names, while arrays use numeric indexes starting from zero. JavaScript also provides many methods for reading and transforming collections. Understanding the difference between objects and arrays is fundamental for working with real application data.
A course application may store one course as an object and all available courses as an array of course objects.
const student = {
name: 'Aman',
score: 88,
course: 'JavaScript'
};
const courses = [
'HTML',
'CSS',
'JavaScript'
];
console.log(student.name);
console.log(courses[2]);The console prints 'Aman' and 'JavaScript'.