# Joining lists with new lines

I am trying to write code to have 2 parallel lists show up on the same line so that they scroll together in a text area.

So if my ListA=[‘apple’,‘banana’,‘corn’] and ListB=[1.25,0.59,0.75], I want them to be displayed as
apple 1.25
banana 0.59
corn 0.75

I feel like I have seen this previously, but I can’t find the code.

Thanks.
-Heather

Unit 6 lesson 11 level 1 is doing something similar. If you looking for documentation on the join function to convert a list to a string, you can find it here.

hmm from my understanding you just want to concatenate separate arrays, in this case i would refrain from using .join() more rather using an iterator to combine two lists together; more rather have a new array in which both are combined into where you can call .split() to produce the proper output

Here’s My Example

``````var a = ["apple", "banana", "corn"];
var b = [1.25, 0.59, 0.75];
/**
* @description Combines two arrays together in string format
* @param {Array} arr1 prefix
* @param {Array} arr2 surrogate
* @returns {Array}
*/
function fuseList(arr1, arr2) {
var arr = [];
for (var i = 0; i < Math.max(arr1.length, arr2.length); i++) {
if (arr1[i] == undefined) { arr1[i] = "N/A" }
if (arr2[i] == undefined) { arr2[i] = "N/A" }
arr.push(arr1[i] + " " + arr2[i]);
}
return (arr);
}
console.log(fuseList(a, b).split("\n"))
``````