Simple Array Manipulation Using Knockout.js (Add, Remove All, Remove Item, Show)
Most of KnockoutJS features involves binding of a viewmodel object to the a view. But there are special cases where in you want to manipulate ordinary arrays without using ko.observableArray(). So to expound more on this post, here's a sample code below: KnockoutJS code: $(document).ready( function () { function ProductViewModel() { //product array this .Products = [{ id: '1' , name: 'Wax' }, { id: '2' , name: 'Cotton Buds' }, { id: '3' , name: 'Nova' }, { id: '4' , name: 'Milo' } ]; //insert product this .Add = function () { console.log( 'Insert Activity' ); this .Products.push({ id: '5' , name: 'Test' }); console.log( 'Total products: ' + this .Products.length); };