有的时候,我们需要操作Object中的key和value,我们需要获取对应的所有keys或者values
1、获取Object对应的keys
/*
*keys-get a array contains all the keys in object*
*@function*
*@param {Object} source*
*@return {Array}*
*@mark we have not check the source is or not object*
*/
ZYC.object.keys = function(source){
var result=[],
key,
_length=0;
for(key in source){
if(source.hasOwnProperty(key)){
result[_length++] = key;
}
}
return result;
};
2、获取Object对应的values
/*
*values-get a array contains all the values in object*
*@function*
*@param {Object} source*
*@return {Array}*
*@mark we have not check the source is or not object*
*/
ZYC.object.values = function(source){
var result=[],key,_length=0;
for(key in source){
if(source.hasOwnProperty(key)){
result[_length++] = source[key];
}
}
return result;
};