如何从我的数组列表中删除`__ob__:Observer`?

huangapple go评论133阅读模式
英文:

how can i remove __ob__: Observer from my array list?

问题

我有一个数组

data = [38589, 3, ob: Observer];

我想要发送一个包含这个数组的 PUT 请求 API,并且得到了一个 400 错误?
是不是这个 __ob__: Observer 的东西正在影响我发送这个数据?如果它是导致错误的原因,我可以知道如何从数组中删除它吗?

英文:

i have an array

data = [38589, 3, __ob__: Observer];

i want to send a put request API with the body sending this array. and got a 400 error?
is it this __ob__: Observer thing is being a problem for me to sending this data? if it's the one that affect the error, can i know how to remove it from my array?

答案1

得分: 13

你可以将它转换为JSON,然后再转回来,如果你想获取数组的最终值而不包括观察者:

const finalData = JSON.parse(JSON.stringify(data));
英文:

You can convert it to JSON and then back, if you want to get the final value of the array without the observer:

const finalData = JSON.parse(JSON.stringify(data));

答案2

得分: 8

我知道这已经过去3个月了,但你也可以使用这个

const final_data = Array.from(data);
英文:

I know this is already 3 months old but you also can use this

const final_data = Array.from(data);

答案3

得分: 1

你可以这样做:

const finalData = { ...data };
英文:

You can do something like this:

const finalData = { ...data }

huangapple
  • 本文由 发表于 2020年1月6日 18:42:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/59610658.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定