FCF 2.0 development in progress...
> > > >
[News] [Packages API] [Downloads] [Donate to the project] [Contacts]

fcf.has() function

boolean fcf.has(object a_object, mixed a_key)

Package: fcf-framework-core

File: fcf-framework-core:fcf.js

Available from version: 2.0.2

Checks if an object contains an element with a given key. Also performed for Map and Set objects


mixed a_object
- Checked object

mixed a_key
- Checked key
- Returns true if the object contains the given key

If the a_object argument is not an object, the function will return false

Example: Function application

console.log(`Is "k1" in {k1: 1}: `, fcf.has({k1: 1}, "k1")) console.log(`Is "k2" in {k1: 1}: `, fcf.has({k1: 1}, "k2")) console.log(`Is 0 in [1]: `, fcf.has([1], 0)) console.log(`Is 1 in [1]: `, fcf.has([1], 1)) { let map = new Map() map.set("k1", "v1"); console.log(`Is "k1" in Map({k1: "v1"}): `, fcf.has(map, "k1")) console.log(`Is "k2" in Map({k1: "v1"}): `, fcf.has(map, "k2")) } { let set = new Set() set.add("k1"); console.log(`Is "k1" in Set(["k1"]): `, fcf.has(set, "k1")) console.log(`Is "k2" in Set(["k1"]): `, fcf.has(set, "k2")) }


Is "k1" in {k1: 1}: true Is "k2" in {k1: 1}: false Is 0 in [1]: true Is 1 in [1]: false Is "k1" in Map({k1: "v1"}): true Is "k2" in Map({k1: "v1"}): false Is "k1" in Set(["k1"]): true Is "k2" in Set(["k1"]): false