myObject = {
"key": "value",
"key2":"value2"
}
Object.keys(myObject);
//console.log(Object.keys(myObject)) = ["key", "key2"]
for (let key in object) {
console.log(key);
console.log(object[key]);
}
const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1)); // expected output: Array ["a", "b", "c"]
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
let data = {
rules: [
{
host: "node-microservice.local",
http: {
paths: [
{
pathType: "Prefix",
path: "/",
backend: {
service: {
name: "proxy",
port: {
number: 80
}
}
}
}
]
}
},
{
host: "node-microservice.local",
http: {
paths: [
{
pathType: "Prefix",
path: "/",
backend: {
service: {
name: "proxy",
port: {
number: 80
}
}
}
}
]
}
}
]
}
function getAllKeys(obj){
let res = []
function getKeys(obj){
for(let key in obj){
res.push(key);
if(typeof obj[key] === "object"){
getKeys(obj[key])
}
}
}
getKeys(obj);
return res;
}
let result = getAllKeys(data).filter((data) => Number.isNaN(Number(data)))
let newResult = [...new Set(result)]
console.log(newValue)