9 examples of 'js prepend to array' in JavaScript

Every line of 'js prepend to array' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
1function append(array, value) {
2 array.push(value);
3 return array;
4};
168function arrayPush(array, values) {
169 var index = -1, length = values.length, offset = array.length
170
171 while (++index < length) {
172 array[offset + index] = values[index]
173 }
174 return array
175}
1758function arrayPush(array, values) {
1759 var index = -1,
1760 length = values.length,
1761 offset = array.length;
1762
1763 while (++index < length) {
1764 array[offset + index] = values[index];
1765 }
1766 return array;
1767}
104function push (array, value) {
105 array.push(value)
106 return array
107}
492private static arrayPush( array: any[], values: any[] ): any[] {
493 var index = -1,
494 length = values.length,
495 offset = array.length;
496
497 while ( ++index < length ) {
498 array[ offset + index ] = values[ index ];
499 }
500 return array;
501}
11function __prepend<a>(value: A, list: List<a>): Array<a> {
12 const itemCount = length(list) + 1
13 const newList = Array(itemCount)
14
15 newList[0] = value
16
17 for (let i = 1; i &lt; itemCount; ++i) newList[i] = list[i - 1]
18
19 return newList
20}</a></a></a>
124function unshift() {
125 return this._applyArrayMethod(arguments, 1, function(arr, args) {
126 return arr.unshift.apply(arr, args);
127 });
128}
7function prepend(x, arr) {
8 if (arguments.length === 1) return function (arrHolder) {
9 return prepend(x, arrHolder);
10 };
11
12 if (typeof arr === 'string') {
13
14 return '' + x + arr;
15 }
16 var clone = arr.concat();
17 clone.unshift(x);
18
19 return clone;
20}
47export function append(array: Arrayable, item: T): Arrayable {
48 return splice(array, array.length, 0, item)
49}

Related snippets