Get object’s children name | JavaScript

I have a function which I’d like to take an object as a parameter. I can’t afford to have the function check for all the possible names of its children, so I’m here looking for an easy way to get those values.

function getObjContents(object) {
    let content /* = list of obj's children */;
    return content;
}

For example I can do something like this:

function getObjContents1(object) {
    let content = object;
    return content;
}
// The problem is that I do not want the everything in the object.

obj = {x: 'Help', y: 'needed', z: 'please'}
getObjContents1(obj)

// returns "{ x: 'Help', y: 'needed', z: 'please' }"

If I do this:

function getObjContents2(object) {
    let content = [object.x, object.y, object.z];
    return content;
}
// I'd have to know beforehand what the object's children names are
// plus its only giving me what x,y and z are assigned to rather than the names

obj = {x: 'Help', y: 'needed', z: 'please'}
getObjContents2(obj)

// returns "[ 'Help', 'needed', 'please' ]"

Is there a way that I can have obj = {x: 'Help', y: 'needed', z: 'please'} in a function that returns only the children names?

// returns "['x', 'y', 'z']"

Answer

I am not sure what you want to get exactly. If you want to get the names of teh props from na object you can define a funciton like this.

function getPropNames(object) {
  return Object.keys(object);
}

likewise you can get values or both too.

function getPropValues(object) {
  return Object.values(object);
}

function getPropNamesAndValues(object) {
  return Object.entries(object);
}