Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Push back to the another array inside map function in JS

I want to do some Calculation inside array, I want to push back to array after iteration.

let dataValue = [90, 150, 180, 200, 230, 270]

dataValue.map((data) => {
  let ValueAs = angleToVaue(data); //calculations I do I get some output like this  example: 1000, 3500, 7000, 6000

  //I want to put back to array 
  let arraValue =[];
  arraValue.push(...ValueAs);

  console.log(...ValueAs); // error: valueAs is not iterable
});

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I guess my answer is what you want to achieve. You have typos in your code and wrong logics

let dataValue = [90, 150, 180, 200, 230, 270]

let angleToVaue = (value) => {
  return value/360
}

let arraValue = [];

dataValue.map((data) => {
let valueAs = angleToVaue(data);
arraValue.push(valueAs);
console.log(valueAs);
console.log('I am the array', arraValue)
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading