Alternative version for Object.values()

前端 未结 11 1726
花落未央
花落未央 2020-11-28 06:13

I\'m looking for an alternative version for the Object.values() function.
As described here the function is not supported in Internet Explorer.

When

11条回答
  •  温柔的废话
    2020-11-28 06:48

    You can get array of keys with Object.keys() and then use map() to get values.

    var obj = { foo: 'bar', baz: 42 };
    var values = Object.keys(obj).map(function(e) {
      return obj[e]
    })
    
    console.log(values)

    With ES6 you can write this in one line using arrow-functions.

    var values = Object.keys(obj).map(e => obj[e])
    

提交回复
热议问题