associative arrays in JavaScript

associative arrays in JavaScript


What is array? Array is a collection of index items and it is a number indexes.

Some of programming language support array as named indexes and the JavaScript not support the array as name indexes and its provide only number indexes but provide this feature using the associative array.

The array with name indexes are called associative array and the associative array is provide a ways to store the information.

The number index array example as given below

    var users = new Object();
    users["Name1"] = "Anil 1";
    users["Name2"] = "Anil 2";
    users["Age"] = 33;
    alert(Object.keys(users).length); //output is 3.
    var length = Object.keys(users).length;  // 3
   
The name index array example as given below

    var users = [];
    users["Name1"] = "Anil 1";
    users["Name2"] = "Anil 2";
    users["Age"] = 33;
    var length = users.length;         // users.length will return 0
    var detail = users[0];             // users[0] will return undefined


I am going to explain the associate array over the database table columns. A table have some columns and its type. i.e.

The empName as text type, empAge as number type and enpDOB as date type.

If we need to find the type of a column that time we can create the associate array. i.e.

var empDetailType = new Array();

empDetailType["empName"] = "ANil";
empDetailType["empAge"] = 30;
empDetailType["empDOB"] = "10/03/1984";

console.log("Find the emp age type :" + empDetailType["empAge"]);


ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Google Amazon and Flipkart Book Store!

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.
ASK Questions
SQL Server NodeJs TypeScript JavaScript Angular SQL Server My Book