向对象添加新的键值对-REACT NATIVE

时间:2020-04-16 07:58:58

标签: javascript

我想问问是否有人可以帮助执行以下操作。

如何将新的键值对添加到从API提取的数组中的现有对象中。 基本上,从API提取后,我有一个具有响应的数组名称utils。

// utils = [ 
{
 id: 1,
 item: 10,
 name: "candybar" 
},
{
 id: 2,
 item: 12,
 name: "whitechocolatebar"
}
]

现在我写了一些条件语句,如下所示:

for (i in utils){

 if(utils[i].name == "candybar"){

  utils.push({ new_name : "Candy Bar" });

 }else if(utils[i].name == "whitechocolatebar"){

  utils.push({ new_name : "White Chocolate Bar" });

 }else{

  utils.push(utils[i].name);

 }

}

现在这给了我:

utils = [
{
 id: 1,
 item: 10,
 name: "candybar" 
},
{
 id: 2,
 item: 12,
 name: "whitechocolatebar"
},
{
 new_name: "Candy Bar"
},
{
 new_name: "White Chocolate Bar"
}
]

但是我想以以下方式使用数组工具:

utils = [
{
 id: 1,
 item: 10,
 name: "candybar" ,
 new_name: "Candy Bar"
},
{
 id: 2,
 item: 12,
 name: "whitechocolatebar",
 new_name: "White Chocolate Bar"
}]

有人可以帮助我实现这一目标吗?

致谢,谢谢。

1 个答案:

答案 0 :(得分:0)

您可以这样做

WARNING: "IOP00710261: (INTERNAL) Number of invocations is already zero, but 
another invocation has completed" 
org.omg.CORBA.INTERNAL:   vmcid: SUN  minor code: 261  completed: Yes 
       at com.sun.corba.se.impl.logging.ORBUtilSystemException.numInvocationsAlreadyZero (Unknown Source) 
       at  com.sun.corba.se.impl.logging.ORBUtilSystemException.numInvocationsAlreadyZero (Unknown Source) 
       at com.sun.corba.se.impl.orb.ORBImpl.finishedDispatch(Unknown Source) 
       at com.sun.corba.se.impl.orb.ORBImpl.releaseOrDecrementInvocationInfo(Unknown Source) 
       at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.releaseReply(Unknown Source) 
       at org.omg.CORBA.portable.ObjectImpl._releaseReply(Unknown Source) 
[...] 
相关问题