Konckout学习——observableArray随笔

1、indexof

  The indexOf function returns the index of the first array item that equals your parameter. For example,myObservableArray.indexOf('Blah') will return the zero-based index of the first array entry that equalsBlah, or the value -1 if no matching value was found.  

  个人理解:observableArray.indexOf(key)函数返回的是observableArray数组里面第一个和“key”相同的数组项的索引(即下标),如果数组里面没有与“key”相同的数组项,则返回“-1”。例如:

1 var strObservableArray = ko.observableArray(['bin','int','int','lao']);
2 alert(strObservableArray.indexOf('int'));//输出“1”
3 alert(strObservableArray.indexOf('abc'));//输出“-1”

2、slice(tart,end)

  The slice function is the observableArray equivalent of the native JavaScript slice function (i.e., it returns the entries of your array from a given start index up to a given end index). CallingmyObservableArray.slice(...) is equivalent to calling the same method on the underlying array (i.e.,myObservableArray().slice(...)).

  参考:

  JavaScript中的slice:https://www.baidu.com/link?url=S9Apxg_qRI5Y30Z4-52aKUe1DECUBMsnPM0vElh1A5dXw_1e56nzL0QGbYSzJoA3vZ__KC4koNo5kUfikHY1U_&wd=&eqid=c39b3d760000e2e60000000455a8b383

  个人理解:slice(tart,end)将返回数组中从start起到end的数组项组成的新数组。

 

  

posted @ 2015-07-17 15:59  PorkMannon  阅读(546)  评论(0编辑  收藏  举报