Skip to content

Instantly share code, notes, and snippets.

@syedjafer
Created August 29, 2022 14:02
Show Gist options
  • Save syedjafer/f8eca58d5baf089f78feec721b20e627 to your computer and use it in GitHub Desktop.
Save syedjafer/f8eca58d5baf089f78feec721b20e627 to your computer and use it in GitHub Desktop.
const data = [5, 4, 3, 2, 1];
// Usage 1 -
data.forEach(val => console.log("Usage 1", val));
// Usage 2 - Mutating(changing the array value inplace)
data.forEach((val, index) => {
data[index] = val * val;
})
console.log("Inplace value changes, ", data);
// Functionality check on return value.
const result = data.forEach((val) => {
val*val;
})
console.log("Result of return value is, ", result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment