0

I have a array object and i have use map to multiply over each value

Myobject :

[{key: "Labour Cost", value: "118"}, {key: "Transport Cost", value: "118"}, {key: "Material Cost", value: "118"}]

function to calculate and merge as key value pair

const calculate = (elementID, i) => {
let mainRow = document.getElementById(elementID);
if (mainRow != null) {
  let qty = mainRow.querySelectorAll('[name=quantity]')[0].value;
  row[i].costRow.map((vl) => {
    const multiplyResult = qty * vl.value;
    object = Object.assign({}, {vl[key]: multiplyResult}); // **getting error here**
    
  });
  console.log(object);
}
}

Expected output :

[{key: "Labour Cost", value: "1146"}, {key: "Transport Cost", value: "123"}, {key: "Material Cost", value: "2334"}]
1
  • Could you please include the relevant HTML in the question? Commented Mar 30, 2021 at 9:14

1 Answer 1

1

Since key is not a variable (object property) you can try the following:

object = Object.assign({}, {[vl['key']]: multiplyResult});

Note: Since you are not returning anything from .map() you can use .forEach().

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.