GithubHelp home page GithubHelp logo

javascript-map's Introduction

Understanding Map in Javascript

JavaScript’s map function is extremely useful, but it can also be a bit confusing when you’re just starting out with programming.

What,Why,When Map?

What ?

The Map object holds key-value pairs. Any value (both objects and primitive values) may be used as either a key or a value.

Why?

It is datastructure to solve real world problems.

When ?

creating Map

   let map =  new Map();  // Here creating map object and map methods to iterate over map
   
     
   

Methods

1. Map.prototype.clear()

   Removes all key/value pairs from the Map object.

2. Map.prototype.delete(key)

 Removes any value associated to the key and returns the value that Map.prototype.has(key) would have previously returned.

3. Map.prototype.has(key)

will return false afterwards.

4. Map.prototype.entries()

 Returns a new Iterator object that contains an array of [key, value] for each element in the Map object in insertion order.

5. Map.prototype.forEach(callbackFn[, thisArg])

Calls callbackFn once for each key-value pair present in the Map object, in insertion order. If a thisArg parameter is provided to forEach, it will be used as the this value for each callback.

6. Map.prototype.get(key)

Returns the value associated to the key, or undefined if there is none.
Map.prototype.has(key)

Returns a boolean asserting whether a value has been associated to the key in the Map object or not.

7. Map.prototype.keys()

Returns a new Iterator object that contains the keys for each element in the Map object in insertion order.

8. Map.prototype.set(key, value)

 Sets the value for the key in the Map object. Returns the Map object.

9. Map.prototype.values()

 Returns a new Iterator object that contains the values for each element in the Map object in insertion order.

10. Map.prototype@@iterator

javascript-map's People

Contributors

prashantb2991 avatar

Watchers

James Cloos avatar Prashant Biradar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.