From 2e11dcb1ea4ef09993ab46e50b95327e30f2b2b5 Mon Sep 17 00:00:00 2001 From: Debalina Mukherjee Date: Sat, 9 Feb 2019 15:02:26 -0800 Subject: [PATCH] Add mdn link for map function (#29883) Add resources section and include mdn link for map function --- .../javascript/es6/map-function/index.md | 62 ++++++++++--------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/guide/english/javascript/es6/map-function/index.md b/guide/english/javascript/es6/map-function/index.md index 188295dbf7..79a4e70aaa 100644 --- a/guide/english/javascript/es6/map-function/index.md +++ b/guide/english/javascript/es6/map-function/index.md @@ -1,29 +1,33 @@ ---- -title: Map Function ---- - -## The Map Function - -The `map()` function is used for creating a new array from an existing one, applying a function to each one of the elements of the first array. - -The original syntax of the map function is: -```javascript - let new_arr = arr.map(function callback(currentValue, index, array) { - // Do some stuff with currentValue (index and array are optionals) - }) -``` -* `new_arr` - the new array that is returned -* `ar`r - the array to run the map function on -* `currentValue` - the current value being processed -* `index` - the current index of the value being processed -* `array` - the original array - -### Example (ES6): - -```javascript -const myArray_1 = [1, 2, 3, 4]; -const myArray_2 = myArray_1.map(el => el * 2); -``` -`myArray_2` will contain the elements: `[2, 4, 6, 8]` - -`map()` is a method of the `Array` object, so to pass that function to an iterable object it is necessary to make the object an Array. +--- +title: Map Function +--- + +## The Map Function + +The `map()` function is used for creating a new array from an existing one, applying a function to each one of the elements of the first array. + +The original syntax of the map function is: +```javascript + let new_arr = arr.map(function callback(currentValue, index, array) { + // Do some stuff with currentValue (index and array are optionals) + }) +``` +* `new_arr` - the new array that is returned +* `ar`r - the array to run the map function on +* `currentValue` - the current value being processed +* `index` - the current index of the value being processed +* `array` - the original array + +### Example (ES6): + +```javascript +const myArray_1 = [1, 2, 3, 4]; +const myArray_2 = myArray_1.map(el => el * 2); +``` +`myArray_2` will contain the elements: `[2, 4, 6, 8]` + +`map()` is a method of the `Array` object, so to pass that function to an iterable object it is necessary to make the object an Array. + +### Resources: + + [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)