I have two arrays that I need to merge together.
One array contains numbers, while the other array contains the corresponding titles for those numbers. This data was retrieved from a csv file, hence the current structure of the arrays.
Array 1:
dataResults = [ 0: "494,927", 1: "48,883", 2: "59,976", 3: "1,205,915" ]
Array 2:
dataTitles = [ 0: "News", 1, "Retail", 2: "Real Estate" 3. "Accounting" ]
I want to merge these two arrays into an array of objects, where index 0 contains both 429,927
and the title news
.
Currently, I am populating these arrays by creating variables and adding data from the csv files.
const dataResults = []
const dataTitles = []
dataResults.push =(dataList[1][5], dataList[2][5], dataList[3][5], dataList[4][5])
//console logs = 0: "494,927", 1: "48,883", 2: "59,976", 3: "1,205,915"
dataResults.push = (dataList[0][1], dataList[0][2], dataList[0][3], dataList[0][4])
// console log = 0: "News", 1, "Retail", 2: "Real Estate" 3. "Accounting"
What I've attempted is combining both pushes into one, but this creates additional indexed arrays. For example, 0: "News", 1: "494,927"
instead of having them both as index 0.
My desired outcome is something similar to a JSON object:
0 : [{ title: "News", result: "494,927 }]"
where I can access both results at index zero.