How can I add new array elements at the beginning of an array in JavaScript?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have a need to add or prepend elements at the beginning of an array. For example, if my array looks like below: [ 23 , 45 , 12 , 67 ] And the response from my AJAX call is 34 , I want the updated array to be like the following: [ 34 , 23 , 45 , 12 , 67 ] Currently I am planning to do it like this: var newArray = []; newArray . push ( response ); for ( var i = 0 ; i < theArray . length ; i ++) { newArray . push ( theArray [ i ]); } theArray = newArray ; delete newArray ; Is there any better way to do this? Does JavaScript have any