The “foreach” binding in Knockout js

foreach binding repeat section written inside it. This is useful to rendering table , lists,

Firstly, we will check with static array then we will go dynamic.

1 . Simple Foreach:

For array need to use observableArray instead of observable.

If we break this on table header we have used simple array access without key and on table data <td/> used key value pair for this.

If not using key value pair and need to access value of array use $data.


Next array is employeeList with key pair values. To access values inside loop directly with key.

Another way to render employeeList array is using $data context as we know it refer to current context.

2. Using ‘as’ to provide alias to “foreach” items

Leave a Reply