Create an object out of dot notation

前端 未结 7 1170
小鲜肉
小鲜肉 2021-01-06 01:30

This is a reverse question to this question.

Given an object x={a:1,b:2} and a string c.d=3, modify object x to the following:



        
7条回答
  •  广开言路
    2021-01-06 02:06

    You can do this with lodash.set()

    > l=require('lodash')
    > x={a:1,b:2};
    { a: 1, b: 2 }
    > l.set(x, 'c.d', 3)
    { a: 1, b: 2, c: { d: 3 } }
    

提交回复
热议问题