It's not clear what your question is. Given your object, obj.a.b
would give you "2" just as it is. If you wanted to manipulate the string to use brackets, you could do this:
var s = 'a.b';
s = 'obj["' + s.replace(/\./g, '"]["') + '"]';
alert(s); // displays obj["a"]["b"]