BOSS
BOSS

Reputation: 2951

Javascript Collection Framework

Like Java having its Collection Framework . Is there any api available in Javascript where

we can Store JSON object in map for key value pair and

it will be having sort functionality and

List or Vector functionality where the size will be auto growable and

HashSet/TreeSet functionality to store duplicate free Json Object or item.

EDIT:

ListI terator functionality will be there where we can traverse bi-directionally.

One More functionality it lacking is removal of item from middle of array can be achieved so that it will rearrange after.

Comparator facity will be a added advantage.

Upvotes: 10

Views: 2116

Answers (6)

Ranajit Chandra
Ranajit Chandra

Reputation: 9

You can use the library mentioned below. Just do npm install collectiondatalib.

Features: www.npmjs.com/package/collectiondatalib

It is really easy to use and all collections- searching- and sorting-methods are available.

Upvotes: 1

user377628
user377628

Reputation:

Javascript's built-in array is 'auto-growable', and is actually pretty similar to the functionality you'd get from Collection in Java.

If however you need something like a HashSet, you could take a look at TaffyDB, which is supposed to be a "database" of sorts for Javascript, but I think it works in-memory.

Upvotes: 1

Bergi
Bergi

Reputation: 665040

No. Most of these features are native to JavaScript.

  • every javascript Object is just key-value pairs (and, mostly, a prototype...) - you know JavaScriptObjectNotation?
  • Lists and Vectors are all covered by the native Array type which auto-grows
  • All Arrays inherit the sort() method, with custom comparator methods available
  • ... and you won't need long to find a snippet that removes duplicates from Objects/Arrays. Even with custom comparators.
  • (the edited): All Arrays inherit the splice() method to remove items from indizes
  • ListIterators: As of ES5.1, all Arrays have iteration methods which work great with JavaScript's functional approach

Yet, there are some libraries to extend these features. E.g. underscore.js treats Objects and Arrays both as iterable collections, there exist HashMap implementations for storing values by non-string-keys etc etc. Also, nearly all of the MVC frameworks implement their own collection objects (for models) to keep up with changes on them.

Upvotes: 4

Tim Down
Tim Down

Reputation: 324627

I've implemented HashTable with arbitrary keys and HashSet in my jshashtable.

Upvotes: 2

sultan
sultan

Reputation: 6058

Try to look at Backbone JS I think you can use its models and collections. Web site http://backbonejs.org/ and tutorials here http://backbonetutorials.com/

Thanks,

Sultan

Upvotes: 1

AlexR
AlexR

Reputation: 115378

ExtJs (definitely) and (I think) jQuery have such functionality.

Upvotes: 1

Related Questions