This article mainly introduces the JS table simulation method, which involves the operation skills for generating, adding, and deleting javascript tables. it has some reference value, for more information about how to simulate JS tables, see the examples in this article. Share it with you for your reference. The specific method is as follows:
ListScript function List () {this. listSize = 0; this. pos = 0; this. dataStore = []; // Initialize an empty array to save the list element this. clear = clear; this. find = find; this. toString = toString; this. insert = insert; this. append = append; this. remove = 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
0) {-- this. pos; //} function next () {// if (this. pos <this. listSize-1) {++ this. pos; //} function currPos () {return this. pos;} function 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: 'duqiang', sex: 'male'}); list. append ({name: 'huahua ', sex: 'Female}); list. append ({name: '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
I hope this article will help you design javascript programs.