Convert Knockout object with Observables to regular objects

knockout-2.0, knockout-mapping-plugin, knockout.js

Solution

Try this:

ko.toJS(currentOrder);

or

ko.toJSON(currentOrder);

Knockout docs here.

Problem

I have an object like below. ``` var order = function (data) { this.OrderId = data.Id; this.CustomerName = ko.observable(data.CustomerName); this.CustomerAddress = ko.observable(data.CustomerAddress); this.CustomerPhone = ko.observable(data.CustomerPhone); this.TotalPrice = ko.observable(data.TotalPrice); this.Cancelled = ko.observable(data.Cancelled); this.Pizzas = ko.observableArray(); }; ``` In my VM: ``` var currentOrder = new model.Order({}); ``` When this object gets modified from the UI, everything works fine. My problem comes in when I want to pass this object to my data layer to get saved. It comes in like: Obviously, I can't pass this to my data layer. Is there an easy way to strip this complex object of all the knockout stuff without manually writing a big mapper?

Original source