I have the following code.
function postResponseMap (options) { const data=options.postResponseMapData[0].data[0].data var record=[] var key= new Object()for(let i=0;i<options.postResponseMapData[0].data[0].data.length;i++){
//while(i> options.postResponseMapData[0].data[0].data.length){
key[options.postResponseMapData[0].data[0].data[i].name] = options.postResponseMapData[0].data[0].data[i].values
return key
//return data[i]
i=i+1
}}
- The goal
- I'm trying to flatten the JSON to be Name:Values
- Way I'm attempting to go about it
- Go through each of the objects in postResponseMapData[0].Data[0].data to find those pieces of information to create a key:value pair
- What doesn't look to be happening.
- When I run my code, I only get the first value
- When I tried returning "i" it doesn't iterate or increment
- Since it's not iterating/incrementing, I'm only getting the first value
- What I've done so far
- I tried to use for(x of y) the area that I needed to look for either wasn't iterable or didn't iterate when it meant to
- I tried using a while loop which also didn't iterate and only gave me the first value
- My question
- What am I doing wrong
- Is there a better way to accomplish this?