To use the hasOwnProperty
function from the Underscore library in TypeScript, you would need to first ensure that you have installed and imported the Underscore library. Assuming you have done that, you can then make use of the hasOwnProperty
function as follows:
index.ts416 chars18 lines
In the code above, we are first importing the Underscore library using the import * as _ from "underscore";
statement. We then create an object obj
with properties a
, b
, and c
. We are then checking if obj
has an own property a
and d
by calling the _.hasOwnProperty(obj, propName)
function. If obj
has the given property, the function returns true
, otherwise it returns false
. We then log appropriate messages to the console based on the returned values.
gistlibby LogSnag