想知道两个数组内的元素相加的js怎么写

https://img4.mukewang.com/5bc6e763000112de05000460.jpg

凤凰求蛊
浏览 918回答 1
1回答

LEATH

var a = [5, 6, 7, 8];var b = [-1, 2, -3, -4];function getResult(a, b) {&nbsp; var c = [];&nbsp; if (a.length === b.length) {&nbsp; &nbsp; for(var i = 0; i < a.length; i++) {&nbsp; &nbsp; &nbsp; c[i] = a[i] + b[i];&nbsp; &nbsp; }&nbsp; }&nbsp; return c;}alert(getResult(a, b));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript