* Converts an object to an array. * @param {IArrayLike |string} object The object to convert to an * array. * @return {!Array } The object converted into an array. If object has a * length property, every property indexed with a non-negative number * less than length will be in
(object)
| 834 | * @template T |
| 835 | */ |
| 836 | function toArray(object) { |
| 837 | const length = object.length; |
| 838 | |
| 839 | // If length is not a number the following is false. This case is kept for |
| 840 | // backwards compatibility since there are callers that pass objects that are |
| 841 | // not array like. |
| 842 | if (length > 0) { |
| 843 | const rv = new Array(length); |
| 844 | for (let i = 0; i < length; i++) { |
| 845 | rv[i] = object[i]; |
| 846 | } |
| 847 | return rv; |
| 848 | } |
| 849 | return []; |
| 850 | } |
| 851 | exports.toArray = toArray; |
| 852 | |
| 853 |