How to get the key value from nested object

前端 未结 5 971
刺人心
刺人心 2020-12-06 15:32

I am having below object where I am trying to get all the id values.

[{
    \"type\": \"test\",
    \"id\": \"100\",
    \"values\": {
        \"name\": \"A         


        
5条回答
  •  心在旅途
    2020-12-06 16:22

    function getIds(obj) {
      for (var x in obj) {
        if (typeof obj[x] === 'object') {
          getIds(obj[x]);
        } else if (x === 'id') {
          console.log(obj.id);
        }
      }
    }
    

提交回复
热议问题