• Convert Array of the object to Object

    Type Parameters

    • T extends Record<K, unknown>

    • K extends string | number | symbol = keyof T

    Parameters

    Returns Record<string, T>

    Example

     const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];
    const obj = arrayToMap(arr, 'name');

    console.log(obj);
    // {
    // 'john': {name: 'john'},
    // 'chris': {name: 'chris'},
    // 'sravan': {name: 'sravan'},
    // 'hoon': {name: 'hoon'}
    // }
  • Convert Array of the object to Object

    Type Parameters

    • T extends Record<K, unknown>

    • K extends string | number | symbol = keyof T

    Parameters

    • arr: T[]
    • selector: string
    • fallbackSelector: K

    Returns Record<string, T>

    Example

     const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];
    const obj = arrayToMap(arr, 'name');

    console.log(obj);
    // {
    // 'john': {name: 'john'},
    // 'chris': {name: 'chris'},
    // 'sravan': {name: 'sravan'},
    // 'hoon': {name: 'hoon'}
    // }
  • Convert Array of the object to Object

    Type Parameters

    • T extends Record<K, unknown>

    • K extends string | number | symbol = keyof T

    Parameters

    • arr: T[]
    • selector: string
    • selector2: string
    • combineKey: true

    Returns Record<string, T>

    Example

     const arr = [{name: 'john'}, {name: 'chris'}, {name: 'sravan'}, {name: 'hoon'}];
    const obj = arrayToMap(arr, 'name');

    console.log(obj);
    // {
    // 'john': {name: 'john'},
    // 'chris': {name: 'chris'},
    // 'sravan': {name: 'sravan'},
    // 'hoon': {name: 'hoon'}
    // }

Generated using TypeDoc