how to create array object in loop without extar key?

By Drop Shadow

I am creating a array object without loop like below :

    var data = [];
    var obj = {};
    obj["key1"] = 'val 1';
    obj["key2"] = 'val 2';
    data.push(obj);

The above code produce me Array[Object] but when I am trying to create this in loop like below :

var data = [];
for (var i = 0; i < len; i++) {
    var obj = {};
    obj["key1"] = 'val 1';
    obj["key2"] = 'val 2';
    data.push(obj);

}

It produce me Array[] , in that 2nd array there is an extra index. So how can I get the array like below :

Array[Object,Object,Object,]

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273