Phone API Reference - Extended - util.forceArray
util.forceArray
Description
Returns an array.
Basic Example:
var newArray = util.forceArray(value[, key]); |
If called with a single argument of an array, returns the argument forced into an array. Otherwise, returns a new array containing argument.
Also can be called with an object and property name. In this case, it uses object[propertyName] as the target.
If value (or value[key]) is undefined, returns an empty array.
Parameters
Name | Required | Type | Default | Description |
---|---|---|---|---|
value | Yes | Value to be forced into an array. | ||
key | No | string | If provided, value[key] is forced into an array. |
Examples
util.forceArray returns an array
var param = 'foo'; util.forceArray(param); |
util.forceArray returns an array, takes an object as the first parameter
var param = {'foo' : 'bar'}; util.forceArray(param, 'foo'); |