获取对象中所有key值

let obj = {
          name:'hhh',
          per:{
            tel:'111',
            sex:'nv',
            hh:{
              see:'hahhaha',
              kkk:'ji',
              ww:{
                mm:'..',
                df:'dfd'
              }
            }
          }
        }
        let arr = []
        function getKeys(oneObj) {
          for(let i in oneObj){
            if(typeof oneObj[i] != 'object'){
              arr.push(i)
            }else{
              arr.push(i)
              getKeys(oneObj[i])
            }
          }
          return arr
        }
       let arrs = getKeys(obj);
        console.log(arrs,'asasas')
        let arr1 = []
        function getKeys1(oneObj) {
          let queen = []
          queen.push(oneObj)
          while (queen.length > 0){
            let tag = queen.shift()
            for (let i in tag){
              if(typeof tag[i] != 'object'){
                arr1.push(i)
              }else{
                arr1.push(i)
                queen.push(tag[i])
              }
            }
          }
          return arr1
        }
        let arrs1 = getKeys1(obj);
        console.log(arrs1,'asasas1')

 

posted @ 2021-01-04 10:04  薄荷凉凉凉  阅读(637)  评论(0编辑  收藏  举报