javascript - Taking 3 array elements and making them a single formatted string -


i'm running ajax request returns json data:

{ "error":0, "fleet":[   {      "fleet_uid":859805,      "purpose":0,      "ower":1,      "time":520,      "con_time":647,      "from":[         6,         300,         2      ],      "target":[         6,         300,         6      ],      "start_user_id":20457507089,      "target_user_id":20510481089,      "start_planet_name":"tweenis12",      "target_planet_name":"p23808"   },   {      "fleet_uid":859803,      "purpose":0,      "ower":1,      "time":508,      "con_time":647,      "from":[         6,         300,         2      ],      "target":[         6,         300,         6      ],      "start_user_id":20457507089,      "target_user_id":20510481089,      "start_planet_name":"tweenis12",      "target_planet_name":"p23808"   } ], "count":2 } 

i need target information inside fleet property. depending on time, there might no fleet entries , there might 10+.

inside target property 3 entries. need merge 3 entries single string formatted xx_xxx_xx

being unfamiliar js , jquery, i'm not sure how this.

try this,

var json = {"error":0,"fleet":[{"fleet_uid":859805,"purpose":0,"ower":1,"time":520,"con_time":647,"from":[6,300 ,2],"target":[6,300,6],"start_user_id":20457507089,"target_user_id":20510481089,"start_planet_name":"tweenis12" ,"target_planet_name":"p23808"},{"fleet_uid":859803,"purpose":0,"ower":1,"time":508,"con_time":647,"from" :[6,300,2],"target":[6,300,6],"start_user_id":20457507089,"target_user_id":20510481089,"start_planet_name" :"tweenis12","target_planet_name":"p23808"}],"count":2};  var arr = []; $.each(json.fleet, function(){     var value = this.target;     arr.push(value[0] + '_' + value[1] + '_' + value[2]);        }); alert(arr); 

demo in fiddle


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -