10 examples of 'jquery find object in array by property value' in JavaScript

Every line of 'jquery find object in array by property value' 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
7export function findObject (array, property, value) {
8 for (let i = 0; i < array.length; i++) {
9 if (array[i][property] === value) {
10 return array[i]
11 }
12 }
13
14 return null
15}
191function findObjByProperty (array, propName, value) {
192 for (let i = 0; i < array.length; i++) {
193 if (array[i][propName] === value) {
194 return array[i];
195 }
196 }
197 return null;
198}
60function find(array, byProperty, condition) {
61 if (!array || array.length === 0) {
62 return;
63 }
64
65 var i = array.length - 1,
66 result = byProperty ? array[i][byProperty] : array[i];
67 if (byProperty) {
68 while (i--) {
69 if (condition(array[i][byProperty], result)) {
70 result = array[i][byProperty];
71 }
72 }
73 }
74 else {
75 while (i--) {
76 if (condition(array[i], result)) {
77 result = array[i];
78 }
79 }
80 }
81 return result;
82}
58function findBy(arr, prop, val) {
59 return arr[findIndexBy(arr, prop, val)]
60}
39function findInArray(arr, propName, propValue) {
40 for (var i = 0; i < arr.length; i++)
41 if (arr[i][propName] == propValue)
42 return arr[i];
43
44 // will return undefined if not found; you could return a default instead
45}
387function findObject(list, name, key) {
388 for (const obj of list) {
389 if (obj.name === name) {
390 if (obj[key]) {
391 return obj[key];
392 }
393 return obj;
394 }
395 }
396 return null;
397}
55function findByAttr (array, attr, value) {
56 return array.find(i => i.getAttribute(attr) === value)
57}
101function propertyArray(object, key) {
102 return object != null ? object[key] : null;
103}
101export function getProperty(propertyName: string, object: T) {
102 let parts = propertyName.split('.'),
103 length = parts.length,
104 i;
105
106 for (i = 0; i < length; i++) {
107 object = object[parts[i]];
108 }
109
110 return object;
111}
96value: function findAllInObject(object, valueOBj, isMulti) {
97
98 for (var objKey in object) {
99 this.performSearch(object[objKey], valueOBj, object[objKey]);
100 if (!isMulti && this.results.length == 1) {
101 return this.results;
102 }
103 }
104
105 while (this.objects.length !== 0) {
106 var objRef = this.objects.pop();
107 this.performSearch(objRef._obj, valueOBj, objRef.parent);
108 if (!isMulti && this.results.length == 1) {
109 return this.results;
110 }
111 }
112
113 return this.results;
114}

Related snippets