Reputation: 2735
I am in need of a Javascript data structure which will allow me to insert strings and search for strings efficiently. I have been looking around and the only data structures I have come across are objects and arrays. Objects are more used for encapsulation and cannot really be used for searching and using arrays can be slow. Are there any other data structures that will allow me to insert and search strings efficiently? Right now at best I could do a binary search on an array. Any other ideas? Thanks.
Upvotes: 3
Views: 2562
Reputation: 2574
Objects are more used for encapsulation and cannot really be used for searching
That was true in classical languages, not so true in JS.
var obj = { memberone: "value1" }
var value = obj["memberone"];
//value === "value1"
Objects can be searched in JS. Bear with me...
and using arrays can be slow.
Yes, can be - but don't have to be.
Are there any other data structures that will allow me to insert and search strings efficiently?
Data structures? No. Again that is a classical perspective. In JS, it is different.
Check out _underscore.js.
This is a good example of JS flexibility.
Hope that helps. All the best! Nash
Upvotes: 3
Reputation: 4690
There are some more I found after some goggling,
Javascript data structures - a collection object
One more thing you can use json objects and its JavaScript API to manipulate same. Please refer same here
Upvotes: 1