0
What is the difference between arrays and objects
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."
+ 2
Please, specify the programming language. It would be great if you included it in relevant tags instead of "invincible".
+ 1
Javascript