KnockoutJS: Access index of item in array from within the JavaScript template
I populate a list from an array using KnockoutJS: <div data-bind:"foreach: list"> <input type="text" data-bind="value: myText" /> </div> function ViewModel() { self.list = ko.observableArray([ new listItem("sample text") ]); }; function listItem (text) { this.myText = text; }; I can assign an id to the individual instances of my input like so <input data-bind="attr: { id: $index } ... How do I access this index from within my listItem function? I want to be able to do something like function listItem (text) { this.myText = text; this.index = $index; }; in order to use this for further