I am currently working on a task that involves extracting values from objects in a string to perform mathematical operations. While I have managed to retrieve the data and match the values enclosed in brackets, I am facing a roadblock in terms of what steps to take next or whether there might be a more efficient approach to accomplish this. Here is a sample of the scenario I am dealing with:
var array = [{name: M, value: 45},{name: F, value: 23},{name: L, value: 9}]
var string = '( 2 * [M] ) * ( 5 / [F] ) * ( 100 + [L] )'
In essence, I am seeking a solution where I can substitute the value of "M" for "[M]", the value of "F" for "[F]", and so forth within the string formula.