Flatten object to array?

前端 未结 7 1223
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-05 03:21

I\'m using an object as a hash table. I\'d like to quickly print out its contents (for alert() for instance). Is there anything built in to convert a hash into

相关标签:
7条回答
  • 2021-01-05 03:57

    Since you want to alert it out I assume it's not for your production version, and that old browser compatibility is not an issue.

    If this is the case, then you can do this:

    var myHash = ......
    alert(Object.keys(myHash).map(function(key) { return [key, myHash[key]]; }));
    
    0 讨论(0)
提交回复
热议问题