Declaring


Different Dimensions

An array of individual items

var arFruits = ['apple', 'banana', 'orange', 'pear']; 

An array of key-value pairs (or multi-dimensional)

var arPairs = [ 
   ['name', 'Richard'],
   ['country', 'France'],
   ['age', 32],
   ['department', 'sales'],
];

An array of data objects (simple key-value pairs)

var arSimple = { 
   name: 'Richard',
   country: 'France',
   age: 32,
   department: 'sales',
};

An array of data objects (complex)

var arSimple = { 
   { name: 'Richard', age: 32 },
   { name: 'Simon', age: 41 },
   { name: 'James', age: 26 },
};



Use Map Instead

If your data consists of key-value pairs and you need to frequently add or remove items.
If your key is not a string



© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext