Files
30-seconds-of-code/snippets/has-value.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

524 B

title, tags, author, cover, firstSeen
title tags author cover firstSeen
Check if object has value object chalarangelo plant-corner 2023-04-10T05:00:00-04:00

Checks if the target value exists in a JSON object.

  • Use Object.values() to get all the values of the object.
  • Use Array.prototype.includes() to check if the target value is included in the values array.
const hasValue = (obj, value) => Object.values(obj).includes(value);
const obj = { a: 100, b: 200 };
hasValue(obj, 100); // true
hasValue(obj, 999); // false