javascript - JS - Set multidimensional array from AJAX output -


let's receive data jquery ajax output.

var tags = call_ajax('order/get_data', 'user_id=' + $('#user_id').val()); 

outputted string php file :

echo "aldi:01|andi:02|martin:03"; 

so question is, how .split() outputted string(tags) become js array format :

var source: [                 {'value' : 'aldi', 'id' : '01'},                 {'value' : 'andi', 'id' : '02'},                 {'value' : 'martin', 'id' : '03'}             ] 

thanks in advance!

with array map method:

var source = tags.split("|") // first split `|`   .map(function(tag) {     // construct object each part     var parts = tag.split(":");     return { value: parts[0], id: parts[1] };   }); 

Comments

Popular posts from this blog

android - Inheriting from Theme.AppCompat* -

broadcastreceiver - android BOOT_COMPLETED not received if not activity intent-filter -

basic authentication with http post params android -