MultiValue new - Axiom

A MultiValue is an immutable collection of data. This data can be of the following types: Boolean, Date, Number, Reference Object, and String. AxiomObjects cannot be placed into MultiValues directly, they must first be persisted, and then referenced using a Reference Object. A MultiValue property can be instantiated as follows:

var mv = new MultiValue("dogs","cats","mice");

The elements of a MultiValue can be retrieved just like an Array:

var cats = mv[1]; // Gives us "cats"

MultiValues can also be used with Axiom Objects by creating a MultiValue of Reference Objects:

var homepage = root.get("homepage"); // This is an Axiom Object.
var categories = hp.get("category"); // This is an Axiom Object.
var mv = new MultiValue(new Reference(homepage), new Reference(categories));

Elements from a MultiValue of Reference Objects can be retrieved as expected:

var hp = mv[0].getTarget(); // Gives us the homepage, same as root.get("homepage")

Below are the properties and methods available to MultiValues.

Contents

MultiValue.length

Description

MultiValue.length

(Number) - The number of items in this MultiValue.


MultiValue.concat()

Description

MultiValue.concat(mv)

Returns a new MultiValue which is the concatenation of the original MultiValue with the one passed in.

Parameters

  • mv (MultiValue) - The MutiValue to concatenate.

Returns

(MultiValue) - The new MultiValue which is the concatenation of the original MultiValue with the one passed in.


MultiValue.contains()

Description

MultiValue.contains(item)

Returns true if the specified item exists in this MultiValue.

Parameters

  • item (AxiomObject, Boolean, Date, Number, Reference Object, or String) - Item to check.

Returns

(Boolean) - True if specified item exists in this MultiValue.

Notes

It is important to note that when checking a MultiValue of Reference Objects, it is not necessary to pass a Reference Object into contains(). The AxiomObject itself can also be passed to check if a reference to it exists.


MultiValue.join()

Description

MultiValue.join(str)

Returns a string of all the elements in the MultiValue separated by the parameter.

Parameters

  • str (String) - String to separate the elements with.

Returns

(String) - String of all the elements in the MultiValue separated by the parameter.


MultiValue.remove()

Description

MultiValue.remove(item)

Removes the item passed in.

Parameters

  • item (AxiomObject, Boolean, Date, Number, Reference Object, or String) - Item to remove.

Notes

Similar to contains(), when removing an item from a MultiValue of Reference Objects, it is not necessary to pass a Reference Object into remove(). The AxiomObject itself can also be passed to remove it from the MultiValue.


MultiValue.slice()

Description

MultiValue.slice(begin, end)

Returns a new MultiValue consisting of the elements from begin to end.

Parameters

  • begin (Number) - Beginning 0 based index to slice from.
  • end (Number, Optional) - End 0 based index to slice to.

Returns

(MultiValue) - The new sliced MultiValue.


MultiValue.splice()

Description

MultiValue.splice(index, num, replacement)

Returns a new MultiValue where num items starting from index are removed, and optionally replaced with replacement.

Parameters

  • index (Number) - Starting 0 based index at which removal should begin.
  • num (Number) - Number of items to remove.
  • replacement (MultiValue, Optional) - MultiValue to replace the removed elements with.

Returns

(MultiValue) - The new spliced MultiValue.

Notes

This does not work like JavaScript Array splice, since MultiValues are immutable. Instead, it returns what the modified Array would return. Also, you cannot pass any number of third parameters, you can only pass one MultiValue, whose elements will replace the removed items.


MultiValue.type()

Description

MultiValue.type()

Returns the type of this MultiValue.

Returns

(String) - The type of this MultiValue.