Answers for "javascript array vs object"

1

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] };
Posted by: Guest on February-03-2021

Code answers related to "javascript array vs object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language