javascript - Moving an array element from [1] to [0] -


you'd think it'd easiest thing in world, can't find solutions don't involve complications don't need or use approaches don't understand.

i have array of objects in unity, 3 positions in array. each time script run, among other things, cube in question set [1], new cube created in front of cube , set [2], , previous cube, if there one, set [0]. result of this, array should updating cubes activated player shifting down array. works fine in respects except [0] keeps returning null on debug.

since cube before 1 in question set [1], first step in code change [0]/ i've been trying with;

objectlist[0] = objectlist[1];  // demotes current object[1] [0]. 

i understand many people have been writing own functions , using splice method avoid running out of array space, don't need kind of complexity. need set object in position [1] position [0]. hope i'm not missing simple keyword in api or anything.

i think you're trying remove front-most item, , "reindex" array, @ index 1 @ index 0. if that's case, want array.shift. removes front-most item.

var items = [1,2,3]  alert(items[0]); // 1  items.shift()  alert(items[0]); // 2  items.shift()  alert(items[0]); // 3 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -