How to get JSON array key and value dynamically using jQuery or JavaScript
<p>I've below JSON, am facing difficulty to get the key and value dynamically from JSON array:</p>

<pre><code>var productJSON = {
    "byProduct": {
        "category": {
            "Entertainment": {
                "TV": 7,
                "Speaker": 24,
                "DVD Player": 5,
                "Home Theater": 4
            },
            "Home": {
                "Sofa Couch": 1,
                "TV Furniture": 4
            },
            "Mobile": {
                "iPhone 5s": 1,
                "Accessories": 4
            }
        }
    }
}
</code></pre>

<p>I'm want key, value from each category and put in two different array, one for product name and another for product count like:</p>

<pre><code>["TV", "Speaker", "DVD Player", "Home Theater","Sofa Couch", "TV Furniture", "iPhone 5s", "Accessories"]

[7, 24, 5, 4,1,4,1,4]
</code></pre>

<p>Can someone help how can I get the output like this?</p>

<p>How can I get these value from above JSON array, below is my code but not able to parse all the item from each category:</p>

<pre><code>var ProductJSON = productJSON.byProduct;
var productsName = [], productCount = [];
Object.keys(ProductJSON.category).forEach(function (v) {
    var k = Object.keys(ProductJSON.category[v])[0];
    productsName.push(k);
    productCount.push(ProductJSON.category[v][k]);
});
console.log(productsName);
console.log(productCount);
</code></pre>

<p>Thanks for your help in advance.</p>