add key pair to each object in array

    0

    0

    majid ghasemi

    The code creates a new DataList that contains a map() function call to v => ({...v, key: v.id}) . The map() function takes in a JavaScript object and returns a new DataList with the same items, but with the key property set to the object's id value.

    Library: react

    const newArr1 = DataList.map(v => ({...v, key: v.id}))
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.