python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
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

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions