10 examples of 'angularjs iterate array of objects' in JavaScript

Every line of 'angularjs iterate array of objects' 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
365(function iterate(obj) {
366
367 let keys = Object.keys(obj);
368 for (let i = 0, l = keys.length; i < l; i++) {
369 let objProp = obj[keys[i]];
370 if (objProp instanceof Object) iterate(objProp);
371 }
372
373 // if there are any existing target objects (objects that we're already observing)...
374 //let c = targets.indexOf(obj);
375 let c = -1;
376 for (let i = 0, l = targets.length; i < l; i++) {
377 if (obj === targets[i]) {
378 c = i;
379 break;
380 }
381 }
382 if (c > -1) {
383
384 // ...then we want to determine if the observables for that object match our current observable
385 let currentTargetProxy = targetsProxy[c];
386 let d = currentTargetProxy.length;
387
388 while (d--) {
389 // if we do have an observable monitoring the object thats about to be overwritten
390 // then we can remove that observable from the target object
391 if (observable === currentTargetProxy[d].observable) {
392 currentTargetProxy.splice(d, 1);
393 break;
394 }
395 }
396
397 // if there are no more observables assigned to the target object, then we can remove
398 // the target object altogether. this is necessary to prevent growing memory consumption particularly with large data sets
399 if (currentTargetProxy.length === 0) {
400 targets[c] = null;
401 //targetsProxy.splice(c, 1);
402 //targets.splice(c, 1);
403 }
404 }
405
406})(targetProp)
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

5function iterate (obj, fn) {
6 if (Array.isArray(obj) === true) {
7 each(obj, (i, idx) => fn(i, idx));
8 } else {
9 each(Reflect.ownKeys(obj), i => fn(obj[i], i));
10 }
11}
276export function objectForEach<V>(
277 obj: { [key: string]: V },
278 cb: (value: V, key: string) => void
279): void {
280 Object.keys(obj).forEach(key => cb(obj[key], key));
281}
84function iterate(obj, cb, depth = 0, toplevel = null) {
85 var ret = [];
86 var pad = ""
87 for (var i = 0;i < depth; i++) {
88 pad += " ";
89 }
90 if (toplevel == null)
91 toplevel = obj;
92 for ([name, value] of Object.entries(obj)) {
93 if (typeof value == "object" && !Array.isArray(value)) {
94 if (value['content'] != null)
95 ret.push(cb(name, value['content'], toplevel));
96 ret = ret.concat(iterate(value, cb, depth + 4, toplevel));
97 }
98 }
99 return ret;
100}
25function forEach(object, callback, context) {
26 var index, length;
27 if (object.length) {
28 if (Array.prototype.forEach) {
29 Array.prototype.forEach.call(object, callback, context);
30 } else {
31 for (index = 0, length = object.length; index < length; index += 1) {
32 callback.call(context || this, object[index], index, object);
33 }
34 }
35 } else {
36 for (index in object) {
37 if (object.hasOwnProperty(index)) {
38 callback.call(context || this, object[index], index, object);
39 }
40 }
41 }
42}
28function iterate(prop, value, options) {
29 if (!value) return value
30
31 let convertedValue = value
32
33 let type = typeof value
34 if (type === 'object') {
35 if (Array.isArray(value)) type = 'array'
36 if (isObservable(value)) type = 'observable'
37 }
38
39 switch (type) {
40 case 'object':
41 if (prop === 'fallbacks') {
42 for (const innerProp in value) {
43 value[innerProp] = iterate(innerProp, value[innerProp], options)
44 }
45 break
46 }
47 for (const innerProp in value) {
48 value[innerProp] = iterate(`${prop}-${innerProp}`, value[innerProp], options)
49 }
50 break
51 case 'array':
52 for (let i = 0; i < value.length; i++) {
53 value[i] = iterate(prop, value[i], options)
54 }
55 break
56 case 'number':
57 if (value !== 0) {
58 convertedValue = value + (options[prop] || units[prop] || '')
59 }
60 break
61 default:
62 break
63 }
64
65 return convertedValue
66}
135iterate(): OpaqueIterator {
136 let { ref, keyFor } = this;
137
138 let iterable = ref.value() as any;
139
140 if (Array.isArray(iterable)) {
141 return iterable.length > 0 ? new ArrayIterator(iterable, keyFor) : EMPTY_ITERATOR;
142 } else if (iterable === undefined || iterable === null) {
143 return EMPTY_ITERATOR;
144 } else if (iterable.forEach !== undefined) {
145 let array: any[] = [];
146 iterable.forEach(function(item: any) {
147 array.push(item);
148 });
149 return array.length > 0 ? new ArrayIterator(array, keyFor) : EMPTY_ITERATOR;
150 } else if (typeof iterable === 'object') {
151 let keys = Object.keys(iterable);
152 return keys.length > 0
153 ? new ObjectKeysIterator(keys, keys.map(key => iterable[key]), keyFor)
154 : EMPTY_ITERATOR;
155 } else {
156 throw new Error(`Don't know how to {{#each ${iterable}}}`);
157 }
158}
5function forEach(haystack, callback, scope) {
6 if (Object.prototype.toString.call(haystack) === '[object Object]') {
7 var keyHaystack = Object.keys(haystack);
8 for (var i = 0, len = keyHaystack.length; i < len; i += 1) {
9 if (Object.prototype.hasOwnProperty.call(keyHaystack, i)) {
10 callback.call(scope, haystack[keyHaystack[i]], keyHaystack[i], haystack);
11 }
12 }
13 }
14 else {
15 for (var i = 0, len = haystack.length; i < len; i += 1) {
16 callback.call(scope, haystack[i], i, haystack);
17 }
18 }
19}
77function iterate(index, array, result) {
78 if (index >= array.length) {
79 return result;
80 } else return callback(array[index], index).then(function (res) {
81 result.push(res);
82 return iterate(index + 1, array, result);
83 });
84}
5function objectToArray(object) {
6 return object.arr;
7}

Related snippets