猿问

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

凤凰求蛊
浏览 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

相关分类

JavaScript
我要回答