10 examples of 'js push to object' in JavaScript

Every line of 'js push to object' 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
23push(object: IStackObject) {
24 this.objects.push(object);
25}
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

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};
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};
42function cloneJSObject(object)
43{
44 var keys = Object.keys(object);
45 var result = { };
46
47 for (var i = 0, length = keys.length; i < length; i++) {
48 var key = keys[i];
49 result[key] = object[key];
50 }
51
52 return result;
53}
173function push(stack, value) {
174 return stack("push")(value);
175}
107value: function push(obj) {
108 return this.results.push(obj);
109}
88export function safePush(obj, prop, val) {
89 if (!obj[prop]) obj[prop] = [];
90 obj[prop].push(val);
91}
98function push(collection, object) {
99 Array.prototype.push.call(collection, object);
100 collection.trigger('add', object);
101}
265function push(obj: any, path: any, ...args: any[]): void {
266 var options: ObjectPathModule.IObjectPathOptions = args[args.length-1];
267
268 if (isObject(options)) {
269 if (!('ownPropertiesOnly' in options)) {
270 options = defaultOptions;
271 } else {
272 args.pop();
273 }
274 } else {
275 options = defaultOptions;
276 }
277
278 var arr = get(obj, path, void 0, options.ownPropertiesOnly);
279 if (!isArray(arr)) {
280 arr = [];
281 set(obj, path, arr, false, options);
282 }
283
284 arr.push.apply(arr, args);
285}
36function pushOrCreate(dict, val) {
37 if (!_.isArray(dict.objects[dict.key])) {
38 dict.objects[dict.key] = [];
39 }
40 dict.objects[dict.key].push(val);
41}

Related snippets