Assign unique ids to your array elements.
/aye/aye-deed/ - you know, id in its past tense, with the suffix -ed. hah, Get it? Hmm, nevermind...
element: {}- A single item in an ided list. It has anidandvalueproperty.id: stringvalue: any
index: number- The position of an element in the list. Like an array's index.list: {}- Instance ofIdedclass.*- Optional|- Or
new Ided(*any[]) => list- Creates a new ided list. Optional array argument to fill the initial list.Ided.parse(element[]) => list- Converts an element array into an ided list. You can turn it back into an element array withlist.toArray().list.insert(value, *index|element) => element- Insert thevalueat positionindexor before theelementor at the end if the second argument is omitted. Negative values defines the position from the end of the list. Returns the inserted element. 1list.length- A property (number) representing the number of elements in the list.list.indexOf(element) => index- Gets theindexof an element by itsidorvalue. Returns-1otherwise. 1list.at(index) => element|null- Gets theelementby itsindexor position in the list. 1list.find(element) => element|null- Yes. This looks funny but check 1. It's likeindexOfbut returns an element instead of an index. If you need a more verbose finder, uselist.search().list.delete(*index|element) => element|null- Deletes element from the list. Returns the deleted element. Deletes the last element if no argument is supplied. 1list.search((element, index) => truthy|falsy) => element|null- Returns theelementof when the callback returnstruthy. Loop ends when it does.list.some((element, index) => truthy|falsy) => boolean- Checks if at least one of the elements passes the callback. Loop ends when it does.list.every((element, index) => truthy|falsy) => boolean- Checks if all of the elements pass the callback.list.map((element, index) => value) => new Ided()- Returns a new ided list from callback's results. Id's stay the same.list.filter((element, index) => truthy|falsy) => new Ided- Returns a new ided list, a subset filtered by the callback. Id's stay the same.list.toArray(*(element, index) => any) => any[]- Returns an array from callback's results. Default callback:element => element. Only returns a copy of the list's internal array to avoid unexpected side effects. NOT a deep copy.
- This
elementargument can be just an object with an id ({id: 'a12'}) or with a value ({value: 'hi'}). If element has both properties, the method will only use theid.