0

What is the difference between arrays and objects

31st Oct 2020, 9:18 PM
Emmanuel Ezoba
Emmanuel Ezoba - avatar
3 Answers
+ 4
Objects are key-value pairs containers: var person = { age: 42, name: "Kev", isAlive: true } person.age // 42 persone["name"] // "Kev" person.length // undefined Arrays are special objects that only accept numeric keys (aka indices), starting from 0. They represent an ordered list of data, have a self-updated length property and custom methods (see SoloLearn's tutorial). var array = ["HTML", "CSS", 25, false, "Javascript"]; array[0] // "HTML" array[3] // false array.length // 5 https://www.sololearn.com/learn/JavaScript/1242 "In JavaScript, arrays always use numbered indexes. It is better to use an object when you want the index to be a string (text). Use an array when you want the index to be a number."
3rd Nov 2020, 11:33 PM
Kevin ★
+ 2
Please, specify the programming language. It would be great if you included it in relevant tags instead of "invincible".
1st Nov 2020, 2:49 AM
Kevin ★
+ 1
Javascript
1st Nov 2020, 8:11 AM
Emmanuel Ezoba
Emmanuel Ezoba - avatar