Skip to content
Advertisement

How to exclude keys from a map and display only the values?

I have an Object obj as below:

const obj = {
         Hostname: "abc"
         id: 189883
         message: "error message"
         name: "script name"
};
  1. I want to exclude the key Hostname and it value.
  2. I only want to capture the values excluding keys such that the output looks as below: 189883:error message:script name

The final output should be a string. I have written the following code but it is creating array element for every letter

const resultObj = Object.values(vascoResponse.rows[0]obj).map((row) =>
  Object.values(row).filter((val) => val)
);

Advertisement

Answer

Use Object.values()

const objec = {
  Hostname: "abc",
  id: 189883,
  message: "error message",
  name: "script name"
};
res = Object.values(objec).filter((o,i) => o != "abc" ).join(":")
console.log(res)
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement