Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.getOwnPropertyNames = Object.getOwnPropertyNames || function (object) {
- var props = [];
- for (var i in object) {
- if (object.hasOwnProperty(i)) {
- props.push(i);
- }
- }
- return props;
- };
- Object.keys = Object.keys || function (object) {
- var keys = [];
- for (var i in object) {
- keys.push(i);
- }
- return keys;
- };
- Object.getPropsAndValues = function (object) {
- var result = '';
- for (var i in obj) {
- if (object.hasOwnProperty(i)) {
- result += i + ': ' + '\n';
- }
- }
- // strip unneccessary newline at end
- result = result.replace(/\n$/);
- };
- // Console
- >>> var obj = {a: 1, b: 2};
- >>> Object.prototype.c = 3;
- >>>
- >>> Object.getOwnPropertyNames(obj);
- ["a", "b"]
- >>> Object.keys(obj);
- ["a", "b", "c"]
- >>> Object.getPropsAndValues(obj);
- "a: 1
- b: 2"
Add Comment
Please, Sign In to add comment