পৃষ্ঠাসমূহ

Search Your Article

CS

 

Welcome to GoogleDG – your one-stop destination for free learning resources, guides, and digital tools.

At GoogleDG, we believe that knowledge should be accessible to everyone. Our mission is to provide readers with valuable ebooks, tutorials, and tech-related content that makes learning easier, faster, and more enjoyable.

What We Offer:

  • 📘 Free & Helpful Ebooks – covering education, technology, self-development, and more.

  • 💻 Step-by-Step Tutorials – practical guides on digital tools, apps, and software.

  • 🌐 Tech Updates & Tips – simplified information to keep you informed in the fast-changing digital world.

  • 🎯 Learning Support – resources designed to support students, professionals, and lifelong learners.

    Latest world News 

     

Our Vision

To create a digital knowledge hub where anyone, from beginners to advanced learners, can find trustworthy resources and grow their skills.

Why Choose Us?

✔ Simple explanations of complex topics
✔ 100% free access to resources
✔ Regularly updated content
✔ A community that values knowledge sharing

We are continuously working to expand our content library and provide readers with the most useful and relevant digital learning materials.

📩 If you’d like to connect, share feedback, or suggest topics, feel free to reach us through the Contact page.

Pageviews

Wednesday, March 8, 2017

Prototype - Hash Processing

Hash can be thought of as an associative array binding unique keys to values. Only difference is that you can use any string as an index instead of just using a number as index.

Creating a Hash

There are two ways to construct a Hash instance −
  • Use JavaScript keyword new.
  • Using Prototype Utility function $H.
To create an empty hash you call any of the constructor methods without arguments, too.
Following is the example showing how to create hash, setting values and getting values in a simple way −
// Creating Hash
var myhash = new Hash();
var yourhash = new Hash( {fruit: 'apple'} );
var hishash = $H( {drink: 'pepsi'} );

// Set values in terms of key and values.
myhash.set('name', 'Bob');

// Get value of key 'name' as follows.
myhash.get('name');
yourhash.get('fruit');
hishash.get('drink');

// Unset a key & value
myhash.unset('name');
yourhash.unset('fruit');
hishash.unset('drink');
Prototype provides a wide range of methods to evaluate Hash with ease. This tutorial will explain every method in detail with suitable examples.
Here is a complete list of all the methods related to Hash.

Prototype Hash Methods

NOTE − Make sure at least have the version 1.6 of prototype.js.
S.No. Method & Description
1. clone() Returns a clone of hash.
2. each() Iterates over the name/value pairs in the hash.
3. get() Returns the value of the hash key's property.
4. inspect() Returns the debug-oriented string representation of the hash.
5. keys() Provides an Array of keys (that is, property names) for the hash.
6. merge() Merges object to hash and returns the result of that merge.
7. remove() Removes keys from a hash and returns their values. This method has been deprecated in version 1.6.
8. set() Sets the hash key's property to value and returns value.
9. toJSON() Returns a JSON string.
10. toObject() Returns a cloned, vanilla object.
11. toQueryString() Turns a hash into its URL-encoded query string representation.
12. unset() Deletes the hash key's property and returns its value.
13. update() Updates hash with the key/value pairs of object. The original hash will be modified.
14. values() Collects the values of a hash and returns them in an array.

No comments:

Post a Comment