Answers for "typescrip check object contain value"

6

typescript check if object has key

if ('key' in myObj)
Posted by: Guest on June-21-2020
1

js does object contain value

// You can turn the values of an Object into an array.
// Then test that a value is present:

// This assumes, that the Object is not nested
// and the value is an exact match:

var obj = { a: 'test1', b: 'test2' };

// Note that an array can only have positive index's; so
// checking for a negative index is a super valid way for getting a
// boolean value as a result for the check.
if (Object.values(obj).indexOf('test1') > -1) {
   console.log('Value exists!');
}
Posted by: Guest on October-13-2020

Code answers related to "typescrip check object contain value"

Code answers related to "Javascript"

Browse Popular Code Answers by Language