Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Removing items from a list #40

Closed
hij1nx opened this Issue · 2 comments

2 participants

@hij1nx

IDEA

What do you think about a removeItems method? This could remove a rage, for instance...

removeItems()

Remove all items.

removeItems(n)

Remove all items until n.

removeItems(Ln, Un)

Remove all items between Lower bound and Upper bound.

PROBLEM

Since there is no removeItems method, I've been looping over the items array and removing each one with removeItem, for some reason, looping forward removes only every second item! but, looping in reverse from the last one works fine, for instance...

var l = list.items.length
while(l--) {
  list.removeItem(l)
}
@chjj
Owner

Since there is no removeItems method, I've been looping over the items array and removing each one with removeItem, for some reason, looping forward removes only every second item! but, looping in reverse from the last one works fine, for instance...

Because every time you remove and item by index, it gets spliced out, so the items.length changes. If you want to remove all items, you could do list.setItems([]).

I'm okay with a removeItems method. That sounds like a decent idea.

@hij1nx
@chjj chjj closed this in fe08f9e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.