Skip to content

Instantly share code, notes, and snippets.

@siddharth-sunchu
Last active June 26, 2021 22:25
Show Gist options
  • Save siddharth-sunchu/eca09bf44ed6cf20a45db224eb7d33d4 to your computer and use it in GitHub Desktop.
Save siddharth-sunchu/eca09bf44ed6cf20a45db224eb7d33d4 to your computer and use it in GitHub Desktop.
ForEach.js
console.log("********Nested ARRAYS********");
const c = [1, 2, [3, 4]];
const d = [];
c.forEach(el => d.push(el));;
console.log('c => ', c);
console.log('d => ', d);
/*
********Nested ARRAYS********
c => [ 1, 2, [ 3, 4 ] ]
d => [ 1, 2, [ 3, 4 ] ]
*/
d[0] = 0; // => Change the values of outer array
d[2][1] = null; // Change the values of nested array
console.log("---------After modification---------");
console.log('c => ', c);
console.log('d => ', d);
/*
---------After modification---------
c => [ 1, 2, [ 3, null ] ]
d => [ 0, 2, [ 3, null ] ]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment