1

I am working with a firebase database which is returning an 'array-like' object. Is there a way to check if a value exists on any field without looping through and checking each value.

My object looks like this:

{
  0: 44,
  1: 23,
  2: 16,
  3: 31
}

and I want to push another random number to the object but I need to check whether or not it exists first.

mattc19
  • 618
  • 1
  • 9
  • 22
  • What have you tried so far? And basically you want to check if a match is found, if not then you want to add it? http://stackoverflow.com/questions/35948669/how-to-check-if-value-exists-in-object-using-javascript – NewToJS Dec 30 '16 at 21:14
  • 3
    `var isValuePresent = Object.values(myObject).indexOf(valueSearchingFor) > -1` – Mr. Polywhirl Dec 30 '16 at 21:15
  • @Mr.Polywhirl You have move your comment into answer. – cn007b Dec 30 '16 at 21:21
  • @VladimirKovpak This is why I have included the URL into my comment since Mr.Polywhirl decided to remove the url and just post the answer. – NewToJS Dec 30 '16 at 21:24
  • 1
    @NewToJS Sorry, question is closed. If you vote to close, it is good etiquette not to add an answer to the question. There was already a question that existed on this subject matter. – Mr. Polywhirl Dec 31 '16 at 00:33
  • @Mr.Polywhirl I know. I have linked to the same answer you decided to copy/paste from... No reason to say sorry to me. I didn't just try take credit for an existing answer. – NewToJS Dec 31 '16 at 00:43
  • 1
    @VladimirKovpak Guess I responded to the wrong person… – Mr. Polywhirl Dec 31 '16 at 01:03
  • @Mr.Polywhirl It's ok!) i saw your reply... – cn007b Dec 31 '16 at 15:33

0 Answers0