对象之间的对象转换 javascript
object conversion between objects javascript
如何从
更改对象
const ob = {
"61ac2727bc40d842e43c8726": {
nama: {
value: "dianaasdasd",
},
username: {
value: "diana",
},
email: {
value: "diana@gmail.com",
error: false,
},
userlevel: {
value: "karyawan",
},
password: {
value: "************************************************************",
},
jenis_kelamin: {
value: "Perempuan",
},
alamat: {
value: "sasddad",
},
},
};
删除“61ac2727bc40d842e43c8726”,值和return对象如下
如何转换为
this image
https://i.stack.imgur.com/6Qi1C.png
您可以像这样生成对象:
const { '61ac2727bc40d842e43c8726': {...obj} } = ob;
let newObj = {};
for(let key in obj){
newObj[key] = obj[key].value
}
你可以这样做
const ob = {
"61ac2727bc40d842e43c8726": {
nama: {
value: "dianaasdasd",
},
username: {
value: "diana",
},
email: {
value: "diana@gmail.com",
error: false,
},
userlevel: {
value: "karyawan",
},
password: {
value: "************************************************************",
},
jenis_kelamin: {
value: "Perempuan",
},
alamat: {
value: "sasddad",
},
},
};
// remove 61ac2727bc40d842e43c8726
const obWithoutKey = Object.values(ob)[0];
// extract key values
const obExpected = Object.entries(obWithoutKey)
.reduce((acc, [key, val])=>{
console.log(key, val)
acc[key]=val.value
return acc;
}, {})
console.log(obExpected)
如何从
更改对象const ob = {
"61ac2727bc40d842e43c8726": {
nama: {
value: "dianaasdasd",
},
username: {
value: "diana",
},
email: {
value: "diana@gmail.com",
error: false,
},
userlevel: {
value: "karyawan",
},
password: {
value: "************************************************************",
},
jenis_kelamin: {
value: "Perempuan",
},
alamat: {
value: "sasddad",
},
},
};
删除“61ac2727bc40d842e43c8726”,值和return对象如下 如何转换为
this image
https://i.stack.imgur.com/6Qi1C.png
您可以像这样生成对象:
const { '61ac2727bc40d842e43c8726': {...obj} } = ob;
let newObj = {};
for(let key in obj){
newObj[key] = obj[key].value
}
你可以这样做
const ob = {
"61ac2727bc40d842e43c8726": {
nama: {
value: "dianaasdasd",
},
username: {
value: "diana",
},
email: {
value: "diana@gmail.com",
error: false,
},
userlevel: {
value: "karyawan",
},
password: {
value: "************************************************************",
},
jenis_kelamin: {
value: "Perempuan",
},
alamat: {
value: "sasddad",
},
},
};
// remove 61ac2727bc40d842e43c8726
const obWithoutKey = Object.values(ob)[0];
// extract key values
const obExpected = Object.entries(obWithoutKey)
.reduce((acc, [key, val])=>{
console.log(key, val)
acc[key]=val.value
return acc;
}, {})
console.log(obExpected)