Skip to content

Custom id function #2

@LetsMelon

Description

@LetsMelon

Custom id function

Description

Create the ability to give the function a custom function for generating the id value.

Template:

function(item, params) { ... }

Function parameters

item: item in arr
params: Object, infos from the addIdToArray(...)

Example

The value of id is the hash from the item.

const addIdToArray = require('addidtoarray');

const customIdFunction = (item, params) => {
     return {id: hash(item)};
}

addIdToArray(['Jeff', 'Maria'], 'name', customIdFunction);
/*
 * result:
 *          [ { id: 'jsoj23...4ecoe', name: 'Jeff'}, ... ]
 */

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions