10 examples of 'javascript get value by key in array' in JavaScript

Every line of 'javascript get value by key in array' 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
457export function _IDX__BY__key(array, key, _VAL) {
458 let obj = {}
459 if (array) {
460 for (let IDX = 0; IDX < array.length; IDX++) {
461 const item = array[IDX]
462 const VAL = _VAL ? _VAL(item && item[key], item, key, IDX) : (item && item[key])
463 if (!VAL) continue
464 obj[VAL] = IDX
465 }
466 }
467 return obj
468}
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

16function getValue (value, key) {
17 if (!value) return value
18 if (value instanceof Map) {
19 return value.get(key)
20 }
21 if (value instanceof Set) {
22 return key
23 }
24 return value[key]
25}
184function getValue (object, key) {
185 return object == null ? undefined : object[key]
186}
456function getValue(object, key) {
457 return object == null ? undefined : object[key];
458}
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}
14function getValue<T, K extends keyof T>(obj: T, key: K) {
15 return obj[key];
16}
826function get(obj, key) {
827 console.assert(key in obj, 'Bad cursor refine: \'' + key + '\' not found in ', obj);
828 return obj[key];
829}
29get(key) {
30 var index = this.keys_.indexOf(key);
31 if (index == -1) {
32 return undefined;
33 }
34 return this.values_[index];
35}
215function get( key ){
216 var keys = key.split("/");
217 switch( keys.length ){
218 case 1: return o[key];
219 case 2: return o[keys[0]][keys[1]];
220 case 3: return o[keys[0]][keys[1]][keys[2]];
221 case 4: return o[keys[0]][keys[1]][keys[2]][keys[3]];
222 }
223}
39export function get(obj, key) {
40 return obj instanceof Map ? obj.get(key) : obj[key];
41}

Related snippets