我在串联Java脚本中的对象时遇到问题
例如:
var firstObj = {};
firstObj.info = ["sam","kam"];
var secObj = {};
secObj.info = ["ram","dam"];
我需要的输出:
firstObj.info = ["sam","kam","ram","dam"];
它实际上就像连接firstObj和secondObj并在
<newObj>
或firstObj
中获取结果一样,我们如何实现呢? 最佳答案
使用concat:
var firstObj = {};
firstObj.info = ["sam","kam"];
var secObj = {};
secObj.info = ["ram","dam"];
var result = firstObj.info;
result = result.concat(secObj.info);
// result = {"sam","kam","ram","dam"}
http://jsbin.com/ahaxu3
关于javascript - javascript中对象串联的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4874818/