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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -