将两个 json/javascript 数组合并为一个数组 [英] Merge two json/javascript arrays in to one array

查看:30
本文介绍了将两个 json/javascript 数组合并为一个数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个 json 数组,例如

I have two json arrays like

var json1 = [{id:1, name: 'xxx' ...}]
var json2 = [{id:2, name: 'xyz' ...}]

我希望它们合并为单个数组

I want them merge in to single arrays

var finalObj = [{id:1, name: 'xxx' ...},{id:2, name: 'xyz' ...}]

推荐答案

您想要 concat 方法.

You want the concat method.

var finalObj = json1.concat(json2);

这篇关于将两个 json/javascript 数组合并为一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆