JustinJDavies
JustinJDavies

Reputation: 2693

How can I UNION two arrays in JSONNET?

If I have two arrays, for example,

local array1 = [0,6,12];
local array2 = std.range(10,15);

and I want an array [0,6,10,11,12,13,14,15] (not concerned specifically about ordering of the elements, just don't want duplicates)

How can I perform this as a union operation that will work for any two arrays of numbers?

Upvotes: 1

Views: 969

Answers (1)

Jon Davies
Jon Davies

Reputation: 487

JSonnet has the function std.setUnion for this use-case. Your result can be found with:

local result = std.setUnion(array1, array2);

See the JSonnet Standard Library reference for more details.

Upvotes: 2

Related Questions