JavaScript

Create an associative array in Javascript

In this tutorial, we are going to see how to create an associative array in Javascript. Arrays in javascript are not like arrays in any other programming language. These are just objects with extra functionality that make them feel like an array.

And to create an associative array with a key-value pair, it is possible to use only objects.
 

How to Create an associative array in Javascript
let obj = {};
obj['name'] = 'Alex Travis';
obj['age'] = 25;
obj['address'] = 'Paris, France';
obj['function'] = ['Developer', 'Administrator', 'Marketer'];

console.log(obj);

Output:

Object {
  name: "Alex Travis"
  age: 25
  address: "Paris, France"
  functions: ["Developer", "Administrator", "Marketer"]
}
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *