요구사항 :
객체 예:
var student = {
name : "홍길동",
sex : "남",
age : 24 };
Sample Output: name,sex,age
코드 :
function _keys(obj)
{
if (!isObject(obj)) return [];
if (Object.keys) return Object.keys(obj);
var keys = [];
for (var key in obj) if (_.has(obj, key)) keys.push(key);
return keys;
}
function isObject(obj)
{
var type = typeof obj;
return type === 'function' || type === 'object' && !!obj;
}
console.log(_keys({red: "#FF0000", green: "#00FF00", white: "#FFFFFF"}));
결과 :
red,green,white
등록된 댓글이 없습니다.