-1

let's suppose I have the following object:

k = {
  name : 'Sam',
  age : 20,
  interests : " ... "
  friends: " ... "
};

How to get all the objects properties without using the Object.keys() function in the ouptup format:

['name', 'age', 'interests' ...]

Note: don't mark my question as duplicate and provide a link to an answer with the Object.keys() function

John P
  • 1,159
  • 2
  • 18
  • 44

1 Answers1

1
var keys = [];
for (var key in k){
    keys.push(key);
}

For more complicated objects than your example, you may want to check k.hasOwnProperty(key) in that loop before adding it.

Paul
  • 35,689
  • 11
  • 93
  • 122