JavaScript Associative Arrays

Implement Associative Arrays In JavaScript Part II of Array Series

An array specifies a variable that can be indexed as a list in rows and columns. Associate array stores a collection of named key and value pairs.

The first index is zero as is common in most programming languages. JavaScript objects can be used as associative arrays.

An array is a data structure consisting of a collection of elements which are values or variables.

Common Functions For Manipulating Associative Arrays In JavaScript

Common Array Functions

Ojamboshop.com Learning JavaScript Associative Array Functions
Name Description Example
Object.assign() Copies properties to target object from source objects Object.assign(pickup_truck2, pickup_truck);
Object.entries() Generates array of key and value pairs let pt = Object.entries(pickup_truck);
Object.values() Generates array of object values let va = Object.values(pickup_truck);
Name Description Example

JavaScript Associative Arrays Snippet

// OjamboShop.com Learning JavaScript Arrays Part II Tutorial //
let pickup_truck = {"brand":"Ford", "model":"F-Series", "year":1984};
console.log(pickup_truck["brand"]);
console.log(pickup_truck.brand);
console.log(pickup_truck.model);
console.log(pickup_truck.year);
let pickup_truck2 = [];
pickup_truck2["brand"] = "Dodge";
pickup_truck2.push({"transmission": "manual"});
console.log(pickup_truck2.brand);
console.log(pickup_truck2.transmission);
Object.assign(pickup_truck2, pickup_truck); // Assign Source To Target
console.log(pickup_truck2.brand);
console.log(pickup_truck2.model);
console.log(pickup_truck2.year);
console.log(pickup_truck2.transmission);
let pt = Object.entries(pickup_truck); // Generate Key Value Pair Array
console.log(pt);
let va = Object.values(pickup_truck); // Generate Values Array
console.log(va);

JavaScript Arrays Part II Code
OjamboShop.com Web IDE JavaScript Arrays Part II Code

JavaScript Arrays Part II Result
OjamboShop.com Web IDE Compiler Displaying JavaScript Arrays Part II Result


Usage

You can use any IDE or text editor and the web browser to compile and execute JavaScript code. For this tutorial, the OjamboShop.com Learning JavaScript Course Web IDE was used to input and compile JavaScript code for the associative arrays.

Open Source

JavaScript follows the ECMAScript standard and is licensed under the W3C Software License by web browser vendors and runtime environment vendors. This allows commercial use, modification, distribution, and allows making derivatives proprietary.

Learn Programming Courses:

Courses are optimized for your web browser on any device.

OjamboShop.com Learning JavaScript Course
OjamboShop.com Learning JavaScript Interactive Online Course

OjamboShop.com Learning Python Course
OjamboShop.com Learning Python Interactive Online Course

OjamboShop.com Learning PHP Course
OjamboShop.com Learning PHP Interactive Online Course

Limited Time Offer:

OjamboShop.com is offering 20% off coupon code SCHOOL for Learning JavaScript Course or Learning Python Course or for Learning PHP Course until End Day 2024.

Learn Programming Ebooks:

Ebooks can be downloaded to your reader of choice.

OjamboShop.com Learning JavaScript Ebook
OjamboShop.com Learning JavaScript Ebook Cover Page
OjamboShop.com Learning JavaScript Ebook
OjamboShop.com Learning Python Ebook Cover Page

OjamboShop.com Learning PHP Ebook
OjamboShop.com Learning PHP Ebook With Sample Page

OjamboServices.com App Development
OjamboServices.com App Development Banner

Conclusion:

JavaScript makes it easy to use associative arrays. Use associative arrays to for a collection of elements in key and value pairs.

Take this opportunity to learn the JavaScript, Python or PHP programming language by making a one-time purchase at Learning JavaScript Course or Learning Python Course or Learning PHP Course. A web browser is the only thing needed to learn JavaScript, JavaScript or PHP in 2024 at your leisure. All the developer tools are provided right in your web browser.

If you prefer to download ebook versions for your reader then you may purchase at Learning JavaScript Ebook or Learning Python Ebook or Learning PHP Ebook

For custom websites, app development and one-on-one tutorials, go to OjamboServices.com.

References: