Use toObject() method in JavaScript