1. Object.keys()
Es5 introduces the Object.keys method, which returns an array whose members are the key names of all traversable (enumerable [enumerable]) properties of the parameter object itself (excluding inherited ones).
(1) Process the object and return an array of enumerable properties
var obj = { foo: 'bar', baz : 42};
Object.keys(obj)
// ["foo", "baz"]
(2) Process the array and return an array of index values
var a = [1, 2, 3, 4]
Object.keys (a)
// ["0", "1", "2", "3", "4"]
(3) Process the string and return an array of index values
var str = 'China 字符串' //中间有几个空格会占用几个索引值
Object.keys(str)
// ["0", "1", "2", "3", "4", "5", "6", "7", "8"]
2. Object.values()
The Object.values method returns an array whose members are the key names of all traversable (enumerable [enumerable]) attributes of the parameter object itself (excluding inheritance).
var obj = { foo: 'bar', baz : 42};
Object.values(obj)
// ["bar", 42]