Skip to content

Instantly share code, notes, and snippets.

@kironroy
Created May 5, 2023 01:33
Show Gist options
  • Save kironroy/370a65a62622053134e8b4b4b8dd0ab2 to your computer and use it in GitHub Desktop.
Save kironroy/370a65a62622053134e8b4b4b8dd0ab2 to your computer and use it in GitHub Desktop.
Array to a new array using a forloop
const yearsArr = [1991, 2007, 1969, 2020];
const agesArr = [];
for (let i = 0; i < yearsArr.length; i++) {
agesArr.push(2037 - yearsArr[i]);
}
console.log(agesArr);
// [46, 30, 68, 17]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment