arrays vs objects in javascript code example
Example: javascript array vs object
// A list of ordered strings is a good case for an array:
const sortedNames = ['Axl', 'Billie', 'Chuck'];
// An item with named properties is a good case for an object:
const box = { height: 4, width: 3, color: 'blue' };
// Two types of collections
// Arrays and objects are two ways of collecting data into a group.
// The data can be primitives (strings, numbers, booleans):
const namesArr = ['Danny', 'Donny', 'Joey', 'Jordan', 'Jonathan'];
const userObj = { name: 'Jamie', age: 42 };
// …or they can be made of other arrays or objects:
const usersArr = [{ name: 'Jim', age: 4 }, { name: 'Al', age: 62 }];
const miscObj = { colors: ['orange', 'red'], numbers: [1, 2, 3] };