data1 = {
title: ' income -1'
,id: '1001'
}
data2 = {
title: ' income -2'
,id: '1002'
}
Want to spell it like this
data3={
{
title: ' income -1'
,id: '1001'
},{
title: ' income -2'
,id: '1002'
}}
Who can answer , thank
CSDN Q & A 2022-02-13 05:10:51 阅读数:347
data1 = {
title: ' income -1'
,id: '1001'
}
data2 = {
title: ' income -2'
,id: '1002'
}
Want to spell it like this
data3={
{
title: ' income -1'
,id: '1001'
},{
title: ' income -2'
,id: '1002'
}}
Who can answer , thank
Plug in one click merge transformation to understand
data3={
{title: ' income -1',id: '1001'},{title: ' income -2',id: '1002'}}
It says , Grammar doesn't make sense , You can turn it into an array
data3 = [ { title: ' income -1', id: '1001', }, { title: ' income -2', id: '1002', },]
Or if you have to have an object , You can write like this
data3 = { data1: { title: ' income -1', id: '1001', }, data2: { title: ' income -2', id: '1002', },}
If it is hierarchical , You can write like this , Easy recursion
data3 = { title: ' income -1', id: '1001', children: [ { title: ' income -1', id: '1001', children: [], }, { title: ' income -2', id: '1002', children: [], }, ],}
var data1 = {title: ' income -1',id: '1001'}var data2 = {title: ' income -2',id: '1002'}var list = [];var list1 = [];list1.push(data1)var list2 = [];list2.push(data2);list.push(data1);list.push(data2);var listobj = {}; for (var key in list) { listobj [key] = list[key]; } console.log(listobj );
var arr = [{ title: ' income -1', id: '1001' }, { title: ' income -2', id: '1002' }] var data3 = Object.assign({}, arr) console.log(data3)
copyright:author[CSDN Q & A],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130510494257.html