Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get all keys in js

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)
Source by prep.soyhenry.com #
 
PREVIOUS NEXT
Tagged: #keys #js
ADD COMMENT
Topic
Name
2+4 =