javascript - add an element to the end of an array, deleting elements from the beginning to maintain the size? -


there variations on question none quite i'm looking for.

what simplest way in javascript add new elements end of array ( my_array.push(x) )?

and if array grows larger size (e.g. 100 elements) shift elements backwards (my_array[1] becomes my_array[0]) in order continue adding end of array.

push returns length of array, can use compare against maximum desired length:

if (a.push(x) > max_length) a.shift();


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -