Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let firstArr = ['category1', 'category2', 'category3', 'category4', 'category5']
- let secondArr = ['value1', 'value2', 'value3', 'value4', 'value5']
- // I created a function to pass all the arrays in
- function populateDictionary(categoryList, key, dataArray, dictionary) {
- dictionary[key] = {}
- for (i=0; i<categoryList.length; i++) {
- dictionary[key][categoryList[i]] = {name: categoryList[i], value: dataArray[i]}
- }
- }
- const dataObject = {}
- populateDictionary(firstArr, 'expenses', secondArr, dataObject)
- console.log(dataObject)
Advertisement
Add Comment
Please, Sign In to add comment