Cast javascript object to array. How to?

前端 未结 6 1612
有刺的猬
有刺的猬 2020-12-08 20:47

I have made this sandbox test:


    
        whatever
        

        
6条回答
  •  隐瞒了意图╮
    2020-12-08 21:27

    Among many other small utilities for manipulating objects and arrays, Underscore.js offers a toArray(obj) helper method. Documentation here: http://underscorejs.org/#toArray

    It's not totally obvious from the way the documentation is written, but it works like a charm on arbitrary objects. When given an object, it iterates over the values and returns a list that contains just those values.

提交回复
热议问题