showing results for - "object defineproperties javascript"
Erika
06 Jun 2019
1const data = [{name: 'john doe', age: 23, hobby: [{name: 'mancing'}] }]
2
3const x= data.map((val) => {
4   const datax = {
5     name: val.name,
6     age: val.age
7   }
8   
9   if(val.hobby.length > 0) {
10      val.hobby.forEach((v) => {
11       Object.defineProperties(datax, {
12        hobby: {
13          value: v.name,
14          writable: true,
15          enumerable: true
16        }
17      })
18     })
19   }
20  
21  return datax
22})
23
24console.log(x)