0

with the below code my expected result is

[{'log1': 'v1'}, {'log2': 'v2'}, {'log3': 'v3'}]

let testArray = ['a', 'b', 'c']
let logArray = [{
  'log1': 'v1'
}, {
  'log2': 'v2'
}, {
  'log3': 'v3'
}]

function arrayTest() {
  let ret = []
  let temp
  testArray.forEach(function(value, outIdx) {
    logArray.forEach(function(value, inIdx) {
      temp = value
    })
    ret.push(temp) // how can i capture the value of "logArray.forEach" to push "ret" array?
  })

  console.log(ret)
}

but this code shows the below result.

[ { log3: 'v3' }, { log3: 'v3' }, { log3: 'v3' } ]

How can i get my expected result?

Sivakumar Tadisetti
  • 4,865
  • 7
  • 34
  • 56

0 Answers0