この記事では、JSテーブルのシミュレーション方法について説明します。参照のためにそれを共有してください。特定の方法は次のとおりです。
<!doctype html> <html> <head> <meta charset = "utf-8"> <title> list </title> <script> function list(){this.listsize = 0; this.pos = 0; this.datastore = []; //空の配列を初期化して、リスト要素を保存するようにthis.clear = clear; this.find = find; this.toString = toString; this.insert = insert; this.append = append; this.remove =削除; this.front = front; this.end = end; this.prev = prev; this.next = next; this.length = length; this.currpos = currpos; this.moveto = moveto; this.getElement = getElement; this.length = length; this.contains = contains; function append(element){this.datastore [this.listsize ++] = element; }; function find(element){for(var i = 0; i <this.datastore.length; i ++){if(this.datastore [i] === element){return i; }} return -1; } function remove(element){var foundat = this.find(element); if(foundat!= -1){this.datastore.splice(foundat、1); this.listsize-;返品要素。 // true trueは元々このようでした、私はそれを要素に変更しました} else {return false; }} function length(){return this.listsize; } function toString(){return this.datastore; } function insert(element、after){var insertsops = this.find(after); if(insertpos!= -1){this.datastore.splice(insertpos+1,0、element); this.listsize ++; trueを返します。 } else {return false; }} function clear(){delete this.datastore; this.listsize = 0; this.pos = 0; this.datastore = []; }関数は(要素){for(var i = 0; i <this.datastore.length; i ++){if(this.datastore [i] === element){return true; }} falseを返します。 } function front(){this.pos = 0; } function end(){this.pos = this.listsize-1; } function prev(){// if(this.pos> 0){-this.pos; //}} function next(){// if(this.pos <this.listsize-1){++ this.pos; //}} function currpos(){return this.pos; }関数moveto(pos){this.pos = pos; } function getElement(){return this.datastore [this.pos]; }} var list = new list(); list.append({name: 'xia guangcheng'、sex: 'male'}); list.append({name: 'Jiang Rongsheng'、sex: 'Male'}); list.append({name: 'du qiang'、sex: 'male'}); list.append({name: 'qiaohua'、sex: 'female'}); list.append({name: 'fang yang'、sex: 'male'}); list.append({name: 'fang yang'、sex: 'male'}); for(list.front(); list.currpos()<list.length(); list.next()){var item = list.getElement(); if(item.sex == 'female'){list.remove(item); }} for(list.front(); list.currpos()<list.length(); list.next()){var item = list.getElement(); console.log(item.name); } </script> </head> <body> </body> </html>この記事がみんなのJavaScriptプログラミングに役立つことを願っています。