পৃষ্ঠাসমূহ

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 - Array Processing

Prototype extends all the native JavaScript arrays with quite a few powerful methods.
This is done in two ways −
  • It mixes in the Enumerable module, which brings a ton of methods in already.
  • It adds quite a few extra methods, which are documented in this section.

Using Iterators

One important support provided by Prototype is that you can use java like iterator in JavaScript. See the difference below −
Traditional way of writing a for loop −
for (var index = 0; index < myArray.length; ++index) {
   var item = myArray[index];
   // Your code working on item here...
}
Now if you are using Prototype, then you can replace the above code as follows −
myArray.each(function(item) {
   // Your code working on item here...
});
Here is the list of all the functions with examples dealing with Array.

Prototype Array Methods

NOTE − Make sure you have the prototype.js version of 1.6.
S.No. Method & Description
1. clear() Clears the array (makes it empty).
2. clone() Returns a duplicate of the array, leaving the original array intact.
3. compact() Returns a new version of the array, without any null/undefined values.
4. each() Iterates over the array in ascending numerical index order.
5. first() Returns the first item in the array, or undefined if the array is empty.
6. flatten() Returns a "flat" (one-dimensional) version of the array.
7. from() Clones an existing array or creates a new one from an array-like collection.
8. indexOf() Returns the position of the first occurrence of the argument within the array.
9. inspect() Returns the debug-oriented string representation of an array.
10. last() Returns the last item in the array, or undefined if the array is empty.
11. reduce() Reduces arrays: one-element arrays are turned into their unique element, while multiple-element arrays are returned untouched.
12. reverse() Returns the reversed version of the array. By default, directly reverses the original. If inline is set to false, uses a clone of the original array.
13. size() Returns the size of the array.
14. toArray() This is just a local optimization of the mixed-in toArray from Enumerable.
15. toJSON() Returns a JSON string.
16. uniq() Produces a duplicate-free version of an array. If no duplicates are found, the original array is returned.
17. without() Produces a new version of the array that does not contain any of the specified values.

No comments:

Post a Comment