A
A
Artem Chernikov2021-06-23 17:44:26
JavaScript
Artem Chernikov, 2021-06-23 17:44:26

How to replace eval in my code?

Is it possible to do something differently instead of putting all the code in eval?
arg1 = 'x'
arg2 = 'y'

function multiply(arg1, arg2){
   let ans = []
   for (let i = 0; i < arr.length; i++) {
      eval(`ans[i] = arr[i].${arg1} * arr[i].${arg2}`)
   }
   return ans
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-23
@Illusive_Sheep

ans[i] = arr[i][arg1] * arr[i][arg2]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question