gpt4 book ai didi

javascript - 将元素和对象添加到数组

转载 作者:行者123 更新时间:2023-11-28 17:29:52 25 4
gpt4 key购买 nike

这就是我正在尝试做的事情:

state={
show:true,
key:'',
sections: [{title:'primary',data:['a','b']},{title:'test',data:[1,2]}]
}

我需要向数据数组添加元素,并且需要向节数组添加对象

最佳答案

尝试以下操作:

var state={
show:true,
key:'',
sections: [{title:'primary',data:['a','b']},{title:'test',data:[1,2]}]
}

state.sections.push({title:'new',data:['e','f']});
console.log(state.sections);

关于javascript - 将元素和对象添加到数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50706229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com