javascript两个数组合并，不是连接，而是相加

javascript两个数组合并，不是连接，而是相加
a=[1,2,3,4,5]
b=[2,4,3,2,1]

3,6,6,6,6

10个回答

`````` a=[1,2,3,4,5]
b=[2,4,3,2,1]
var rst=[];
a.forEach(function(v,index){rst.push(v+b[index])})
console.log(rst)
``````
``````arr3 = [1,2,3];
arr4 = [1,2,3];
let newarr = arr3.map(function(item, index) {
return item + arr4[index]
})
console.log(newarr)
``````

for（int i=0;i<a.length;i++）
{
c[i]=a[i]+b[i];
}

``````a.map((val,index)=>(val+b[index]));
``````

function sum（a,b）{
var c=[];
if(Array.isArray(a)&&Array.isArray(b){

for(var i=0;i<a.length;i++)
for(var j=0;j<b.length;j++){
if(a.length!=b.length){
}else{
if (i==j){
c[i]=a[i]+b[j]
}else{
continue
}
}
}
return c
}
}

function(a,b){
var c = [];
for (var i = 0; i < a.length; i++) {
c[i] = a[i] + b[i];
}
return c;
}

``````a=[1,2,3,4,5]
b=[2,4,3,2,1]
c=a.map((v,i)=>v+b[i]);
console.log(c);

``````

var a = [1,2,3,4];
var b = [1,2,3,4,5,6,7,8,9];
var arr_= [];
if(a.length==b.length){
for (var i=0;i<a.length;i++){
arr_.push(parseFloat(a[i])+parseFloat(b[i]))
}
console.log(arr_)
}else if(a.length<b.length){
for (var i=0;i<a.length;i++){
arr_.push(parseFloat(a[i])+parseFloat(b[i]))
}
for(var j=a.length;j<b.length;j++){
arr_.push(b[j])
}
console.log(arr_)
}else{
for (var i=0;i<b.length;i++){
arr_.push(parseFloat(a[i])+parseFloat(b[i]))
}
for(var j=b.length;j<a.length;j++){
arr_.push(a[j])
}
console.log(arr_)

``````    }
//输出[2,4,6,8,5,6,7,8,9]
``````

int[] a={1,2,3,4,5};

int[] b={4,5,6,7,8};

`````` public class CopyArray {
public int[] add(int[] a, int[] b) {
if (a.length == b.length) {
for(int i=0;i<a.length-1;i++){
a[i]=a[i]+b[i];
if(a[i]>9){
a[i]=a[i]%10;
a[i+1]=a[i+1]+1;
}
}
a[a.length-1]=a[a.length-1]+b[b.length-1];
if(a[a.length-1]>9){
a[a.length-1]=a[a.length-1]%10;
int[] c=new int[a.length+1];
for(int i=0;i<a.length;i++){
c[i]=a[i];
}
c[c.length-1]=1;
return c;
}else{
return a;
}

} else {
int[] bigger = a.length > b.length ? a : b;
int[] smaller = a.length < b.length ? a : b;
int temp = bigger.length - smaller.length;
for(int i=0;i<=smaller.length-1;i++){
bigger[i] = smaller[i] + bigger[i];
if (bigger[i] > 9) {
bigger[i] = bigger[i] % 10;
bigger[i + 1] = bigger[i + 1] + 1;
}
}
for (int i = smaller.length; i < bigger.length-1; i++) {
if (bigger[i] > 9) {
bigger[i] = bigger[i] % 10;
bigger[i - 1] = bigger[i - 1] + 1;
}
}
if (bigger[bigger.length-1] > 9) {
bigger[bigger.length-1] = bigger[bigger.length-1] % 10;
int[] c = new int[bigger.length + 1];
for (int i = 0; i < bigger.length; i++) {
c[i + 1] = bigger[i];
}
c[bigger.length-1] = 1;
return c;
} else {
return bigger;
}
}
}
public static void main(String[] args){
int[] a={1,3,6,8,4,5,7};
int[] b={2,4,6,7,8};
CopyArray copy=new CopyArray();
for(int i=0;i<c.length;i++){
System.out.println(c[i]);
}
}
}
``````

a.concat(b)试试。。

input type=button value=扇区+ onclick="cell.value=cell.value+10"> rn比如cell.value=11111, 那么点击以下文本框内容变成1111110,而不是11120,为什么啊 rn怎么解决 ,而减号是数字的相减
PHP两个数组相加如何合并?
\$a = array('a'=>1,'b'=>2,'c'=>3);   \$b = array('a'=>2,34,4,77,99);   \$c = \$a + \$b;   echo "";   print_r(\$c); 结果: Array (     [a] => 1     [b] => 2     [c] => 3     [0] => 34

ng2中数组合并值相加（根据名称相同合并金额） let data = [ {name:"A",count:15}, {name:"B",count:20}, {name:"A",count:15} ]; let obj = {}; let arr = []; data.forEach(m=>{ let name =
CUDA—两个数组相加

var sumCount=["12","12","13"];//sumCount是以字符串的方式取得的数字数组//rnvar s=0;rn for(i=0;i

javascript两个数组合并及判断数据类型的方法
// javascript里将a,b两个数组合并的方法     var a = [1,4,6,3,7,8,5,76,45];     var b = ["fun","asw","wes","add","apple"];     var c = a.concat( b );        console.log("数组c    "+c); 数组c的内容是 ：  1,4,6,3,7,8,5

var ary=["A","B","C","D"]; var ary2=[1,2,3,4,5,6,]; function aryJoinAry(ary,ary2) { var itemAry=[]; var minLength; //先拿到两个数组中长度较短的那个数组的长度 if(ary.length>ary2.length){ minLength=

string [] a=1,2,4;rnstring [] b=2,3,4,5;rn如何用循环合并成1，2，3，4，5？rn

c++ 合并两个数组
c++ 合并两个数组 题目描述： 两个数组，每个数组的长度均为3，输出合并排序后的数组 示例： 输入： 2 4 6 1 3 5 输出： 1 2 3 4 5 6 #include <iostream> using namespace std;int main() { int a[3], b[3], c[6]; for(int i = 0

①将两个整型升序数据集合A和B合并成一个升序数据集合 例A={3,5,7,8,9,12,16} B={2,4,7,9,11} 结果：C={2,3,4,5,7,7,8,9,9,11,12,16} #include&amp;lt;stdio.h&amp;gt; #define M 7 #define N 5 #主函数 int main(void) { int a[M]={3,5,7,8,9,12,1...

private static JSONArray joinJSONArray(JSONArray array1, JSONArray array2) { StringBuffer sbf = new StringBuffer(); JSONArray jSONArray = new JSONArray(); try { ...

array1 = array("1","2")rnarray2 = array("3","4")rn如何合并这两个数组，构成第三个数组array3，让array3的值如下：rnarray("1","2","3","4")rn????????????????

1.数组的方法concat():concat();方法为赋值并新增，返回一个新数组，只适合无嵌套的数组，concat();会将数组最外层的中括号去掉，然后对其元素进行拷贝。var arr1 = [1,2,3];var arr2 = [3,4,5];var arr = arr1.concat(arr2);//[1,2,3,3,4,5]2.ES6扩展运算符：返回一个新数组var arr1 = [1,2...

JavaScript 小技巧之数组合并

javascript如何合并数组

JavaScript合并两个有序数组

javascript合并两个对象
var a ={"name":"kobe"}; var b= {"age":20}; var c = Object.assign(a,b); //a={"name":"kobe","age":20} //c={"name":"kobe","age":20} var a = {"name": "kobe"}; var b = undefined; var c =
JavaScript——合并两个有序链表

TensorFlow 合并 / 连接 数组
import tensorflow as tfa = tf.Variable([4,5,6]) b = tf.Variable([1,2,3])c = tf.concat(0,[a,b]) init_op = tf.initialize_all_variables() with tf.Session() as sess: sess.run(init_op) print(sess.ru

java 数组相加

A表rnrnKey , numrn1 10rn2 38rn3 8rn4 11rnA表rnKey , numrn1 10rn2 38rn4 11rn6 100rn9 121rnrn求得到rnkey , numrn1 20rn2 76rn3 8rn4 22rn6 100rn9 121rnrn就是相同的KEY num 就相加
javascript怎么实现两个数组中随机两个相加？相加的结果用alet方式进行输出？
javascript怎么实现两个数组中随机两个相加？相加的结果用alet方式进行输出？谢谢