2008-12-02

【程式】JS : 取得部份陣列資料

arrayObject.slice(start,end);

下面來個Sample

var arr = new Array(6);
arr[0] = "Jani";
arr[1] = "Hege";
arr[2] = "Stale";
arr[3] = "Kai Jim";
arr[4] = "Borge";
arr[5] = "Tove";
document.write(arr + '< br />');
document.write(arr.slice(0,1) + "< br />");
document.write(arr.slice(2,4) + "< br />");
document.write(arr);
/*
The output of the code above will be:
Jani,Hege,Stale,Kai Jim,Borge,Tove
Jani
Stale,Kai Jim
Jani,Hege,Stale,Kai Jim,Borge,Tove
*/

【P】取得部份陣列資料

0 comments:

張貼留言