admin管理员组

文章数量:1390555

var dict = {
  'Type1':'.typ1',
  'Type2':'.typ2',
  'Type3':'.typ3'
}

Any chance there's a concise one-liner to produce CSV like following:

".typ1,.typ2,.typ3"
var dict = {
  'Type1':'.typ1',
  'Type2':'.typ2',
  'Type3':'.typ3'
}

Any chance there's a concise one-liner to produce CSV like following:

".typ1,.typ2,.typ3"
Share Improve this question edited Nov 14, 2014 at 21:34 Pointy 414k62 gold badges595 silver badges629 bronze badges asked Nov 14, 2014 at 20:46 RodRod 15.5k35 gold badges134 silver badges264 bronze badges 1
  • 5 Sure: Object.keys(dict).map(function(k){return dict[k];}).join(',');. You're wele. – Felix Kling Commented Nov 14, 2014 at 20:47
Add a ment  | 

2 Answers 2

Reset to default 4
Object.keys(dict).map(function(k){
    return dict[k];
}).join(',');

jQuery solution :

var str = $.map(dict, function(x){return x}).join();

DEMO

本文标签: javascriptTurn dictionary into csvStack Overflow