js-wrench
Version:
JS函数库
18 lines (17 loc) • 483 B
text/typescript
import isObj from './isObj'
/**
* @description 返回object自身可枚举属性
*
* @param {*} obj 要返回可枚举属性的对象
* @return {*} {Array<string>} 返回一个给定对象自身的所有可枚举属性的数组
* @example toKeys({a:1,b:2}) => ["a", "b"]
*/
const toKeys = (obj: any): Array<string> => {
if (!isObj(obj)) return []
let keys: Array<string> = []
for (let key in obj) {
keys.push(key)
}
return keys
}
export default toKeys