简体   繁体   中英

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

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) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM