Muhammad Wakeel
Muhammad Wakeel

Reputation: 3

how to make associative array using loop in javascript

//response = [{"id":"1","created":"26-05-2016"},{"id":"2","created":"25-05-2016"},{"id":"8","created":"21-05-2016"}]

success : function(response){
var obj = JSON.parse(response);

// here i want to make associative array... like array['user'] = id & array['created']..

please help me

Upvotes: 0

Views: 45

Answers (1)

gurvinder372
gurvinder372

Reputation: 68413

simply try this

    var response = [{"id":"1","created":"26-05-2016"},{"id":"2","created":"25-05-2016"},{"id":"8","created":"21-05-2016"}];
    var output = response.map(function(obj){ return { user: obj.id, created: obj.created } })
    
    console.log(output)

Upvotes: 2

Related Questions