Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Script 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.

like image 575
BOSS Avatar asked May 30 '12 06:05

BOSS


3 Answers

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.

like image 172
Bergi Avatar answered Oct 28 '22 20:10

Bergi


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

like image 28
Tim Down Avatar answered Oct 28 '22 18:10

Tim Down


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

like image 1
AlexR Avatar answered Oct 28 '22 20:10

AlexR