创建一个 javascript 数组并保存另一个数据数组以在 Javascript 中创建一个数组。我已经按照以下提到的方式进行了尝试。代码:var vvv=this.new_products.length-this.quote.lines.length; let mmm={}; if(vvv > 0){ for(var i = 0; i <= vvv-1; i++){ mmm ={...this.new_products[this.quote.lines.length+i]}; } } console.log(mmm);例子:this.new_products -> 0: {…} 1: {…} 2: {…} 3: {…}this.quote.lines -> 0: {…} 1: {…}输出应该是 ->mmm-> 0: {…} (this.new_products[2]) 1: {…} (this.new_products[3])当前输出->{product_code: "khdbdvdjlhc de", description: "sscs", note: "csccc", pinned: false, third_party: 0, …}我试过的代码不起作用。请帮我解决这个问题。
2 回答

拉丁的传说
TA贡献1789条经验 获得超8个赞
我假设你需要遗体:
let m = [];
for(var i = 0; i <= vvv - 1; i++){
m.push({...this.new_products[this.quote.lines.length+i]});
}

繁花如伊
TA贡献2012条经验 获得超12个赞
...
您可以像这样使用展开运算符创建浅表副本:
var array = ["thing1", "thing2"];
var array2 = [...array];
如果您需要进行深拷贝,最简单的方法之一是使用 lodash 的 cloneDeep() 函数,如下所示:
import _ from 'lodash';
var array = ["thing1", "thing2"];
var array2 = _.cloneDeep(array);
添加回答
举报
0/150
提交
取消