在JS中组合数组 [英] Combining arrays in JS

查看:131
本文介绍了在JS中组合数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有2个经典和流行阵列:

If you have 2 arrays classical and pop:

classical=["Beethoven","Mozart","Tchaikovsky"];
pop=["Beatles","Corrs","Fleetwood Mac","Status Quo"];

为什么设置 all = classical + pop 它给数组元素中的字符设置一个单独的字符吗?

Why is that when you set all=classical+pop it gives sets character in the array elements an individual character?

如何在不重新输入的情况下纠正这一点,即 all = [Beethoven ,莫扎特,柴可夫斯基,甲壳虫乐队......]

How do you correct this without retyping i.e. all=["Beethoven","Mozart","Tchaikovsky","Beatles"...]

非常感谢提前。

推荐答案

使用Array类的concat()方法将它们组合在一个新变量上:

Use the Array class concat() method to combine them on a new variable:

var all = classical.concat(pop);

这篇关于在JS中组合数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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