Skip to main content

Introduction to map method in Javascript

map is one of the most used, popular array methods in Javascript. It can also be referred as higher order function. Higher order function is a function which returns function or which accepts other functions as arguments.Let's understand about map function

many times you need to take an array and modify it according to your needs and you can easily achieve this with help of map method.

Syntax of map method 
               

map method accepts a callback function which is executed on each of the element of the array. Callback function can also be written using arrow syntax

callback function accepts following arguments

element - It is the current element  being processed in the iteration 

Index -  It is the index of current element being processed and it is    optional

array - array on which the map method was called and it is  optional 
 
let's understand map method with an example 



consider the above example where you have an array and you want to multiply all the elements of array by 2 

Here map method accepts a callback function which is executed on each element of the array. Callback function takes el as argument, which is the current array element in the iteration and multiplies it by 2 and return a new array with all modified values. Thus map method return a new array to result variable with modified values.

If the array consists of multiple objects, then the callback function receives current object in each iteration 

Thus array.map method is very useful when we want to modify array element according to needs and create a new array.

 

Comments

Popular posts from this blog

How to use Google images without copyright issue

Every blogger or youtuber makes use of variety of images in their post,as it enhances the quality of the post and also it is very effective way to make their audience understand.But all the images that you get on google are not free,because some of the images may have copyright.So usage of such images may lead to problems. Hence I try to describe some methods to get free images without copyright , so that you can use those images in your blog or video. Here are some steps to follow 1.  In your PC go to search engine and type the name of the image that you need 2.  click on image button, which will redirect image page. 3.  click on the tools button which is next to settings (for better understanding it is marked in red color) 4.  By clicking on the tools button, you will find,below some options 5. click on the third option i.e usage rights ( for better understanding it is marked in red color) 6. By clicking on the usage rights, you wil...

Integration of tailwind css with react application

 steps 1)  open termianl create react app with npx create-react-app command 2) then install packages with following command  npm i -D tailwindcss postcss-cli autoprefixer 3) then create tailwind config file , with following comman npx tailwind init tailwind.js  --full 4) create post css config file with following command  touch postcss.config.js 5) then finally put follwing code in post css config fil e const tailwindcss = require ( 'tailwindcss' ) module . exports ={ plugins : [ tailwindcss ( './tailwind.js' ), require ( 'autoprefixer' ) ] } 6) then create assests folder and inside it create main.csss and tailwind.css file 7) then in tailwind.css file place the following code 8) place following code in package.json 9th step final in package.json file 9 th step "start" : " npm run watch:css && react-scripts start" , "build" : "npm run build:css &&react-scripts build" , 8th s...

ನಮ್ಮ ಕನ್ನಡ ನಮ್ಮ ಹೆಮ್ಮೆ.

ಇಂದು ನವೆಂಬರ್ 1, ಕನ್ನಡ ರಾಜ್ಯೋತ್ಸವ ! ಎಲ್ಲೆಲ್ಲೂ ಕನ್ನಡದ ಕಲರವ, ಕನ್ನಡ ಹಬ್ಬದ ಸಂಭ್ರಮ. ಅಬ್ಬಾ! ಕನ್ನಡ ಹಾಗೂ ಕರ್ನಾಟಕ ಎಂಬ ಶಬ್ದ ಕಿವಿಗೆ ಬಿದ್ದ ಕೊಡಲೆ ಅದೆನೋ ರೋಮಾಂಚನ ಅದೆನೋ ಆನಂದ. ಕನ್ನಡದ ಹಿರಿಮೆ, ಗರಿಮೆಯನ್ನು ವರ್ಣಿಸಲು ಪದಗಳೇ ಸಾಲುವುದಿಲ್ಲ, ಅಷ್ಟು ಅಧ್ಬುತ ನಮ್ಮ ಕನ್ನಡ. ನಮ್ಮ ನಾಡು  ಅನೇಕ ಸಸ್ಯ ಸಂಪತ್ತು , ಪ್ರಾಣಿ ಸಂಪತ್ತುಗಳಿಂದ ಕೂಡಿದ ಸಂಪದ್ಭರಿತ ನಾಡು. ಕನ್ನಡದ ಹಿರಿಮೆಯನ್ನು , ಎತ್ತರವನ್ನು , ಸಾಂಕೇತಿಕವಾಗಿ ಹೇಳುವ , ಮುಗಿಲು ಮುಟ್ಟವ ಗಿರಿ ಶಿಖರಗಳಿಂದ ಕೂಡಿದ ನಾಡು.ತನ್ನ ಸುಂದರವಾದ   ಹರಿಯುವ ಶಬ್ದದ ಮೂಲಕ, ಕನ್ನಡ ಭಾಷೆಯ ಇಂಪನ್ನು ತಿಳಿಸುವ ನದಿಗಳ ಹಾಗೂ ಭೋರ್ಗರೆಯುವ ರಮಣೀಯ ಜಲಪಾತಗಳ ದಿವ್ಯ ನಾಡು ನಮ್ಮ ಕನ್ನಡ ನಾಡು.ಒಟ್ಟಿನಲ್ಲಿ ನಮ್ಮ ಹೆಮ್ಮೆಯ ಕನ್ನಡ ನಾಡು,ನಿಸರ್ಗ ಸಂಪತ್ತಿಯಿಂದ ಕೂಡಿದ ಸುಂದರ ನಾಡು. ಕಲೆ , ಸಾಹಿತ್ಯ , ಸಂಗೀತ , ನೃತ್ಯ , ವಿಜ್ಞಾನ, ತಂತ್ರಜ್ಞಾನಗಳ ನಿಧಿ ನಮ್ಮ ಹೆಮ್ಮೆಯ ಕನ್ನಡ ನಾಡು.ಈ ಎಲ್ಲ ಕ್ಷೇತ್ರಗಳಿಗೂ ಕರ್ನಾಟಕದ ಕೊಡುಗೆ ಅಪಾರ ಹಾಗೂ ಅದ್ಭುತ.  ಹೀಗೆ ಹೇಳುತ್ತಾ ಹೋದರೆ ಅದಕ್ಕೆ ಕೂನೆಯೆ ಇಲ್ಲ.ಕನ್ನಡದ ಹಿರಿಮೆಯನ್ನು ವರ್ಣಿಸಲು ಪದಗಳೇ ಸಾಲುವುದಿಲ್ಲ.ಇಂತಹ‌ ಅದ್ಭುತ ಕನ್ನಡ ನಾಡಿನಲ್ಲಿ ಜನಿಸಿದ ನಾವೇ ಧನ್ಯರು ! ಕನ್ನಡ ಭಾಷೆ ಅನೇಕ ಸಾಹಿತ್ಯ ರತ್ನಗಳಿಂದ ಶೋಭಿತವಾದ ಸಿರಿವಂತ ಭಾಷೆ.ಸುಮಾರು ಎರಡು ಸಾವಿರ ವರ್ಷಗಳ ದೀರ್ಘ ಇತಿಹಾಸ ಇರುವ ಸುಂದರ ...