-1
var stored_names = {
      332438809: "Bereznyak24",
      489485245: "Bereznyak25"
    }
  if ((data.message.from.id in stored_names) && (data.message.text === "/start")) {
    SendMsg(id, first_reply.text);
  }

How can I check if my object has key (or has not) that's equal to data.message.from.id value that I get later?

Kamil Kiełczewski
  • 85,173
  • 29
  • 368
  • 345
Bereznyak
  • 75
  • 1
  • 13

1 Answers1

1

Your answer should work, as your are using the in keyword (value in stored_names).

Another way to check if the value is amongst the keys is to use Object.key() to enumerate the keys and Array.includes.

Object.keys(arr).includes(value);

See the doc for Object.keys

jo_va
  • 13,504
  • 3
  • 23
  • 47
  • thanks for the reply! Why can't I get this thing working? `if (( Object.keys(stored_names).includes(data.message.from.id) )` – Bereznyak Feb 06 '19 at 22:31
  • You should be good with the code you posted in your question. Verify what data.message.from.id gives you though as well as data.message.text – jo_va Feb 06 '19 at 22:38