0

I have below scenario. i.e i have a object as below.

    var x= {
        "item": {
            "count": 6,
            "type": "product",
            "max": "100",
        },

    }

var loadJson = JSON.parse(x);

now if i have a string like.

var y="item" how can i access loadJson.y.count , I am getting error saying y is undefined.

  • now it is different, I am getting an error undefined if i want to access in above scenario(i have a string data) – Prathipati sathya vinod Nov 15 '17 at 15:02
  • there is no x, you parsed the variable x, and set it to loadJson. so now `loadJson.item` is item. and `loadJson.item.count` is to get to count. – nycynik Nov 15 '17 at 15:36
  • Yes you are right, but i have a scenario where i will get variable from "y" which is string and i need to fetch the value using variable y,This scenario i am facing issue.Please suggest. – Prathipati sathya vinod Nov 15 '17 at 16:28

0 Answers0