I am writing a game for the Windows App store that will use HTML5 and Javascript.
Are there any implementations of ArrayList or LinkedList for this platform? If so could someone give me an example how to use it?
I am writing a game for the Windows App store that will use HTML5 and Javascript.
Are there any implementations of ArrayList or LinkedList for this platform? If so could someone give me an example how to use it?
A JavaScript Array does not have a fixed length and thus can be used like an ArrayList. You just have to use the right methods:
arrayList.Add(element) = array.push(element)arrayList.AddRange(collection) = array.push(element1, element2, ...)Array methods, push can take a variable number of elements to append.arrayList.RemoveRange(index, count) = array.splice(index, count)splice removes the given number of elements (count) at index.arrayList.RemoveAt(index) = array.splice(index, 1):1 as count to splice removes just one element.arrayList.Insert(index, x) = array.splice(index, 0, element)splice also takes a variable number of elements to insert at the index after removing the given number of elements. By removing no elements (passing 0 as count), you can use it to simply insert new elements.All of these methods correctly adjust the length of the array and shift elements around, as opposed to delete array[index]. delete simply removes properties from an object and does not treat arrays differently, so you're left with a "gap".
I figured out my problem! All I want that I can release memory in array. It can be done by using "delete" keyword for each element of array, but array's length is not reduced.
And about Array List in JavaScript, I think the current build-in array is fine. No need to implement more.