- KnockoutJS Tutorial
- KnockoutJS - Home
- KnockoutJS - Overview
- KnockoutJS - Environment Setup
- KnockoutJS - Application
- KnockoutJS - MVVM Framework
- KnockoutJS - Observables
- Computed Observables
- KnockoutJS - Declarative Bindings
- KnockoutJS - Dependency Tracking
- KnockoutJS - Templating
- KnockoutJS - Components
- KnockoutJS Resources
- KnockoutJS - Quick Guide
- KnockoutJS - Resources
- KnockoutJS - Discussion
remove([set of values]) Method
Description
The KnockoutJS Observable remove([set of values]) method removes the items that match a given set of values.
Syntax
arrayName.remove([set of values])
Parameters
This method accepts a parameter in the form of a values set.
Example
<!DOCTYPE html> <head> <title>KnockoutJS ObservableArray remove multiple method</title> <script src = "https://ajax.aspnetcdn.com/ajax/knockout/knockout-3.1.0.js" type = "text/javascript"></script> </head> <body> <p>Example to demonstrate remove([set of values]) method.</p> <button data-bind = "click: removemultiEmp">Remove multiple Emps</button> <p>Array of employees: <span data-bind = "text: empArray()" ></span></p> <script> function EmployeeModel() { this.empName = ko.observable(""); this.chosenItem = ko.observableArray(""); this.empArray = ko.observableArray(['Scott','James','Jordan','Lee', 'RoseMary','Kathie']); this.removemultiEmp = function() { alert("This function is removing multiple matching items e.g.['RoseMary','Lee']."); this.empArray.removeAll(['RoseMary','Lee']); } } var em = new EmployeeModel(); ko.applyBindings(em); </script> </body> </html>
Output
Let's carry out the following steps to see how the above code works −
Save the above code in array-remove-set.htm file.
Open this HTML file in a browser.
Click the Remove multiple Emps Button.
knockoutjs_observables.htm
Advertisements