summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/core/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/core/utils.js')
-rw-r--r--addons/web/static/src/js/core/utils.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/addons/web/static/src/js/core/utils.js b/addons/web/static/src/js/core/utils.js
index a5a5f4eb465..50e54273ac9 100644
--- a/addons/web/static/src/js/core/utils.js
+++ b/addons/web/static/src/js/core/utils.js
@@ -268,6 +268,25 @@ var utils = {
return Math.max(min, Math.min(max, val));
},
/**
+ * Looks through the list and returns the first value that matches all
+ * of the key-value pairs listed in properties.
+ * If no match is found, or if list is empty, undefined will be returned.
+ *
+ * @param {Array} list
+ * @param {Object} props
+ * @returns {any|undefined} first element in list that matches all props
+ */
+ findWhere: function (list, props) {
+ if (!Array.isArray(list) || !props) {
+ return;
+ }
+ return list.filter((item) => item !== undefined).find((item) => {
+ return Object.keys(props).every((key) => {
+ return item[key] === props[key];
+ })
+ });
+ },
+ /**
* @param {number} value
* @param {integer} decimals
* @returns {boolean}