Object.values() (非标准)
2016-06-13 15:51
423 查看
This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility
table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The
returns an array of a given object's own enumerable property values, in the same order as that provided by a
(the difference being that a for-in loop enumerates properties in the prototype chain as well).
enumerable property values found directly upon
is the same as that given by looping over the property values of the object manually.
To add compatible
support it, you can find a Polyfill in the tc39/proposal-object-values-entries or
in the es-shims/Object.valuesrepositories.
Desktop
Mobile
[1] Behind a flag.
[2] See bug 150131.
Enumerability
and ownership of properties
Because this technology's specification has not stabilized, check the compatibility
table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The
Object.values()method
returns an array of a given object's own enumerable property values, in the same order as that provided by a
for...inloop
(the difference being that a for-in loop enumerates properties in the prototype chain as well).
Syntax
Object.values(obj)
Parameters
objThe object whose enumerable own property values are to be returned.
Description
Object.values()returns an array whose elements are strings corresponding to the
enumerable property values found directly upon
object. The ordering of the properties
is the same as that given by looping over the property values of the object manually.
Examples
var obj = { foo: "bar", baz: 42 }; console.log(Object.values(obj)); // ['bar', 42] // array like object var obj = { 0: 'a', 1: 'b', 2: 'c' }; console.log(Object.values(obj)); // ['a', 'b', 'c'] // array like object with random key ordering var an_obj = { 100: 'a', 2: 'b', 7: 'c' }; console.log(Object.values(an_obj)); // ['b', 'c', 'a'] // getFoo is property which isn't enumerable var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } }); my_obj.foo = "bar"; console.log(Object.values(my_obj)); // ['bar'] // non-object argument will be coerced to an object console.log(Object.values("foo")); // ['f', 'o', 'o']
Polyfill
To add compatible Object.valuessupport in older environments that do not natively
support it, you can find a Polyfill in the tc39/proposal-object-values-entries or
in the es-shims/Object.valuesrepositories.
Specifications
Specification | Status | Comment |
---|---|---|
ECMAScript 2017 Draft (ECMA-262) The definition of 'Object.values' in that specification. | Draft | Initial definition. |
Browser compatibility
Desktop Mobile
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 51.0 [1] | 47 (47) | No support | No support | No support [2] |
[2] See bug 150131.
See also
Enumerabilityand ownership of properties
Object.keys()
Object.entries()
Object.prototype.propertyIsEnumerable()
Object.create()
Object.getOwnPropertyNames()
相关文章推荐
- Object.keys()
- Object.getOwnPropertyNames()
- IOS Dev Intro - Object-C Call C C++
- JdbcTemplate 版本4以上的queryforObject和queryforList的实现
- python django form error:module' object has no attribute '_meta'
- [Effective JavaScript 笔记]第31条:使用Object.getPrototypeOf函数而不要使用__proto__属性
- js(javascript)与ios(Objective-C)相互通信交互
- objective-C之NSDate相关类(四)
- objective-C之NSDate相关类(三)
- Windows下的Objective-C集成开发环境(IDE)
- objective-C之NSDate相关类(二)
- PHP 将json的stdClass Object转成数组array 方法二
- Objective-C --- - UITableView 二 对一进行一些属性补充(梳理总结)
- Object 泛型
- Android Studio安装后运行程序时提示Could not reserve enough space for object?
- 论文笔记《Rich Feature Hierarchies for accurate object detection and semantic segmentation》
- Objective-C仿映客跑车动画
- hive脚本出现Error: java.lang.RuntimeException: Error in configuring object和Caused by: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
- Swift与Object-C的区别
- objective-C之NSDate相关类(一)