Tuesday, 18 April 2017

Get the value from associative array in javascript

I want to get the value from array. I am using javascript. My array is

[{"username1" : "123456"},{"username2" : "121"}]

I want to get the value of username1. I want print 123456 using username1. How it possible? Please help me? My code is shown below.

var categories = [];

  categories.push({"username1" : "123456"});

for (var i = 0; i < categories.length; i++) {
for (var categoryid in categories[i]) {
    var category = categories[i][categoryid];
    // log progress to the console
    console.log(categoryid + " : " + category);

}

It shows print all values and object in array.



via Fazil

No comments:

Post a Comment