What’s Objects and Arrays in Javascript or any language? And what are the key roles of them how they differentiated to each other and also how they work?
If object is similar to dictionary then why it’s introduced?
Note: I understand the little bit of the above topic but I am confused what if question arises to me? So, please guide me to understand deeply these topic.
Objects are used to create things that require a feature:
Let’s say that you want to define what a dog is, you need to separate it’s features to it’s number of legs and other stuff etc. In order to do this, you will have to create an object. Arrays on the other hand are just a group of data. Hope this helps.
I’m not sure what a dictionary is in a programming language, I only know JavaScript. In JavaScript, you can have two data types: first is primitives (numbers, strings, …), and everything else is an object. An array is an object, a function is an object, etc. The main difference compared to primitives is that an object can be changed/mutated.
Array - a set of data of the same type, indexed by a non-negative integer
let myArray = ["a", "b", "c", "dog"];
console.log(myArray[3]);
Object - more complex set of data, indexed by key-value pairs
let myObject = { name: "rover", legs: 4};
console.log(myObject.name);
In JavaScript everything is an Object. An object works like a dictionary or hashmap under the covers, so there is no need to separately describe a dictionary or hashmap.