summaryrefslogtreecommitdiffhomepage
path: root/tests/custom/03_stdlib/03_exists
blob: 3d71aa77763e782fbaa12a9aae68e349800afad9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
The `exists()` function checks the existence of the given key within the
given object. If the object contains the given key, `true` is returned,
otherwise `false`.

If the object argument is not an object, `false` is returned as well.

The key argument is converted to a string in case it is not one already.

-- Testcase --
{%
	let obj = {
		"foo":   true,
		"bar":   false,
		"false": null,
		"123":   "a number"
	};

	printf("%.J\n", [
		exists(true, "test"),
		exists(obj, "doesnotexists"),
		exists(obj, "foo"),
		exists(obj, "bar"),
		exists(obj, !true),
		exists(obj, 123)
	]);
%}
-- End --

-- Expect stdout --
[
	false,
	false,
	true,
	true,
	true,
	true
]
-- End --