javascript - How to split two or more address -
i'm getting data server side in format
coll={state:ap,address:['(a14,f4,j.v villa(ac))','(a5,f4,json park(dc))']} and want put address in select box option
select box ----a14,f4,j.v villa(ac) ----a5,f4,json park(dc) what have tried
jquery.each(coll,function(key,value){ var temp_address=value.address.split(','); jquery.each(temp_address,function(key1,value1){ var option = new option(value1, value1); select_purchase.append(jquery(option)); }); i output as
select box ----(a14,f4,j.v villa(ac)) ----(a5,f4,json park(dc)) i want remove round bracket aeound address, afraid use regex because might remove round bracket inside address , can me out efficient insertion of option in select box array.i want because might have large number of address , might slow
update after googling sometime found traditional forloop faster each
a made regex remove outside parenthesis:
var address = address.replace(/^\(|\)$/g,''); this expression can interpreted this:
^ @ start \( parenthesis | or \) parenthesis $ @ end the matching strings replaced ''.
you can call this:
coll.address = coll.address.map(function(s){ return s.replace(/^\(|\)$/g,'') }); note if want remove first , last character, can do
var address = address.slice(1,-1);
Comments
Post a Comment