javascript - Concatenate object property values -
i have javascript object. concatenate property values, say:
tagsarray["1"] = "one"; tagsarray["2"] = "two"; tagsarray["z"] = "zed"; result = "one,two,zed"
just background, have several checkboxes, , need update hidden selectedkeys field. example of server side (asp.net) code + angularjs
<input hidden id="selectedkeys" value="1,5,8"> @foreach (var tag in tagsdictionary) { <input type="checkbox" ng-model="tagsarray['@tag.key']" ng-true-value ="'@tag.key'" ng-false-value ="" ng-change="change(tagsarray)" />@tag.value }
so on each change need update #selectedkeys
value
one possible approach:
var tagsarray = {}; tagsarray["1"] = "one"; tagsarray["2"] = "two"; tagsarray["z"] = "zed"; var result = object.values(tagsarray).join(","); console.log(result); // "one,two,zed"
more on array.prototype.join
, object.values
.
Comments
Post a Comment