8 examples of 'push object in array javascript' in JavaScript

Every line of 'push object in array javascript' 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
this disclaimer
9function insertIntoArray<T>(array: T[], object: T): T[] {
10 return array ? [object, ...array] : [object];
11}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

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}
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}
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}
95var pushOrCreateArrayAt = function pushOrCreateArrayAt(object, key, valueToPush) {
96 // don't need to use hasOwnProp as there is no array in the prototype
97 // but still use it to avoid a warning
98 // const potentialArray = object[key]
99 if (hasOwnProperty.call(object, key)) {
100 // eventually the if is always true
101 object[key].push(valueToPush);
102 } else {
103 // only for the first time
104 object[key] = [valueToPush];
105 }
106};
62var pushOrCreateArrayAt = function pushOrCreateArrayAt(object, key, valueToPush) {
63 // don't need to use hasOwnProp as there is no array in the prototype
64 // but still use it to avoid a warning
65 // const potentialArray = object[key]
66 if (Object.prototype.hasOwnProperty.call(object, key)) {
67 // eventually the if is always true
68 object[key].push(valueToPush);
69 } else {
70 // only for the first time
71 object[key] = [valueToPush];
72 }
73};
23push(object: IStackObject) {
24 this.objects.push(object);
25}

Related snippets