Skip to content


Subversion checkout URL

You can clone with
Download ZIP


exists(key) function #59

joshefin opened this Issue · 7 comments

4 participants


It would be useful to have a store.exists("somekey") function that returns true/false. Getter function can be used but it includes parsing.


Hi guys!

I think I would be a bit surprised if JSON parsing was a bottle neck in any real world usage of store.js. Do you do have such a problem? If you do I can definitely see the value of a store.exists(key). However, if you don't I believe it may be in the interest of the project to avoid adding features without real world needs. Basically in the interest of keeping it lean, avoiding feature creep, and so on.

What do you guys think?



It's not a bottleneck in most cases, but when the data is large (few thousand items) it would be useful to avoid unneeded parsing.


Hmm, are you sure? Like, have you tested that? I would not take it for granted that the CPU bound parsing takes significantly longer than reading the string from disk (if that's how local storage persistence works, I don't know).

You may have a point, but if you haven't collected the data then can you know that there is a need



Here's an attempt at explaining why I'm hesitant adding things without understanding why it's necessary:

First the downsides: every new feature adds complexity, bytes to download (if store.js is used on thousands of sites and downloaded by millions of people every month, then do those bytes become meaningful? Probably. We recently removed support for Firefox 2 and 3 for this reason). It also is another thing to maintain, document, and read up on when you're considering to use the project and are trying to understand it.

However, there may be upsides! And if there are, I'm all for new beneficial features! But we should really know that they are beneficial!

Let me know if you are up to get some data supporting the need, would love to know the performance of read vs parse and if there is a significant bottleneck in either or if they're about the same. If not, I'm going to vote for closing this issue. Oui?




I'm actually facing the same need! I use LocalStorage to store user requested information and I don't want to save a duplicated content. So if an option could exist, I also would be interested!

Based on the ReadMe example:
store.set('tags', ['javascript', 'localStorage', 'store.js'])

How can I check if user input (for example "store.js") exist in store.tags?

Cheers and thank you for your great plugin!


EDIT as closed topic:

Marcus, you've saved my day!
Thank you so much ;-)



Not quite the same issue, but here is what you'd do. Three options I guess:

Just store the tags:


Store all tags in an array:

var tags = store.get('tags') || []
var tagPresent = tags.indexOf('javascript') != -1
store.set('tags', tags)

Store tags in an object

var tags = store.get('tags') || {}
var tagPresent = tags['javascript']
tags['javascript'] = true
store.set('tags', tags)


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.