How to get objects value if its name contains dots with JavaScript?

Spread the love

To get objects value if its name contains dots with JavaScript, we can use square brackets.


For instance, we write

const mydata = { list: [ { "points.bean.pointsBase": [ { time: 2000, caption: "caption text", duration: 5000 }, { time: 6000, caption: "caption text", duration: 3000 }, ], }, ],
};
const smth = mydata.list[0]["points.bean.pointsBase"][0].time;

to get the first entry in list with mydata.list[0]


And we get the "points.bean.pointsBase" property with ["points.bean.pointsBase"].