---
title: Builtin Functions
slug: reference/builtin-functions
docTags: 
createdAt: 2025-09-23T15:08:13.023Z
---

## Builtin Functions

### format

Returns a formatted string. The first argument must be a String object. See [this](docId\:AE7jtYmsLBgwKDjB2FYgA) for more details on formatting.

:::CodeblockTabs
Tengo

```go
a := [1, 2, 3]
s := format("Foo: %v", a) // s == "Foo: [1, 2, 3]"
```
:::

### len

Returns the number of elements if the given variable is array, immutable array, string, bytes, map or immutable map.

:::CodeblockTabs
Tengo

```go
v := [1, 2, 3]
l := len(v) // l == 3
```
:::

### copy

Creates a copy of the given variable. `copy` function calls `Object.Copy` interface method, which is expected to return a deep-copy of the value it holds.

:::CodeblockTabs
Tengo

```go
v1 := [1, 2, 3]
v2 := v1
v3 := copy(v1)
v1[1] = 0
v2[1] // 0; 'v1' and 'v2' referencing the same array
v3[1] // 2; 'v3' not affected by 'v1'
```
:::

### append

Appends object(s) to an array (first argument) and returns a new array object. (Like Go's `append` builtin.) Currently, this function takes array type only.

:::CodeblockTabs
Tengo

```go
v := [1]
v = append(v, 2, 3) // v == [1, 2, 3]
```
:::

### delete

Deletes the element with the specified key from the map type. First argument must be a map type and second argument must be a string type. (Like Go's `delete` builtin except keys are always string). `delete` returns `undefined` value if successful and it mutates given map.

:::CodeblockTabs
Tengo

```go
v := {key: "value"}
delete(v, "key") // v == {}
```
:::

:::CodeblockTabs
Tengo

```go
v := {key: "value"}
delete(v, "missing") // v == {"key": "value"}
```
:::

:::CodeblockTabs
Tengo

```go
delete({}) // runtime error, second argument is missing
delete({}, 1) // runtime error, second argument must be a string type
```
:::

### splice

Deletes and/or changes the contents of a given array and returns deleted items as a new array. `splice` is similar to JS `Array.prototype.splice()` except splice is a builtin function and first argument must an array. First argument must be an array, and if second and third arguments are provided those must be integers otherwise runtime error is returned.

Usage:

`deleted_items := splice(array[, start[, delete_count[, item1[, item2[, ...]]]])`

:::CodeblockTabs
Tengo

```go
v := [1, 2, 3]
items := splice(v, 0) // items == [1, 2, 3], v == []
```
:::

:::CodeblockTabs
Tengo

```go
v := [1, 2, 3]
items := splice(v, 1) // items == [2, 3], v == [1]
```
:::

:::CodeblockTabs
Tengo

```go
v := [1, 2, 3]
items := splice(v, 0, 1) // items == [1], v == [2, 3]
```
:::

:::CodeblockTabs
Tengo

```go
// deleting
v := ["a", "b", "c"]
items := splice(v, 1, 2) // items == ["b", "c"], v == ["a"]
// splice(v, 1, 3) or splice(v, 1, 99) has same effect for this example
```
:::

:::CodeblockTabs
Tengo

```go
// appending
v := ["a", "b", "c"]
items := splice(v, 3, 0, "d", "e") // items == [], v == ["a", "b", "c", "d", "e"]
```
:::

:::CodeblockTabs
Tengo

```go
// replacing
v := ["a", "b", "c"]
items := splice(v, 2, 1, "d") // items == ["c"], v == ["a", "b", "d"]
```
:::

:::CodeblockTabs
Tengo

```go
// inserting
v := ["a", "b", "c"]
items := splice(v, 0, 0, "d", "e") // items == [], v == ["d", "e", "a", "b", "c"]
```
:::

:::CodeblockTabs
Tengo

```go
// deleting and inserting
v := ["a", "b", "c"]
items := splice(v, 1, 1, "d", "e") // items == ["b"], v == ["a", "d", "e", "c"]
```
:::

### type\_name

Returns the type\_name of an object.

:::CodeblockTabs
Tengo

```go
type_name(1) // int
type_name("str") // string
type_name([1, 2, 3]) // array
```
:::

### string

Tries to convert an object to string object. See [Runtime Types](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
x := string(123) //  x == "123"
```
:::

Optionally it can take the second argument, which will be returned if the first argument cannot be converted to string. Note that the second argument does not have to be string.

:::CodeblockTabs
Tengo

```go
v = string(undefined, "foo")  // v == "foo"
v = string(undefined, false)  // v == false
```
:::

### int

Tries to convert an object to int object. See [this](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
v := int("123") //  v == 123
```
:::

Optionally it can take the second argument, which will be returned if the first argument cannot be converted to int. Note that the second argument does not have to be int.

:::CodeblockTabs
Tengo

```go
v = int(undefined, 10)    // v == 10
v = int(undefined, false) // v == false
```
:::

### bool

Tries to convert an object to bool object. See [this](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
v := bool(1) //  v == true
```
:::

### float

Tries to convert an object to float object. See [this](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
v := float("19.84") //  v == 19.84
```
:::

Optionally it can take the second argument, which will be returned if the first argument cannot be converted to float. Note that the second argument does not have to be float.

:::CodeblockTabs
Tengo

```go
v = float(undefined, 19.84)    // v == 19.84
v = float(undefined, false)    // v == false
```
:::

### char

Tries to convert an object to char object. See [this](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
v := char(89) //  v == 'Y'
```
:::

Optionally it can take the second argument, which will be returned if the first argument cannot be converted to float. Note that the second argument does not have to be float.

:::CodeblockTabs
Tengo

```go
v = char(undefined, 'X')    // v == 'X'
v = char(undefined, false)  // v == false
```
:::

### bytes

Tries to convert an object to bytes object. See [this](docId\:smONYFzO12nj6JXYY8eu4) for more details on type conversion.

:::CodeblockTabs
Tengo

```go
v := bytes("foo") //  v == [102 111 111]
```
:::

Optionally it can take the second argument, which will be returned if the first argument cannot be converted to float. Note that the second argument does not have to be float.

:::CodeblockTabs
Tengo

```go
v = bytes(undefined, bytes("foo"))    // v == bytes("foo")
v = bytes(undefined, false)           // v == false
```
:::

If you pass an int to `bytes()` function, it will create a new byte object with the given size.

:::CodeblockTabs
Tengo

```go
v := bytes(100)
```
:::

### time

Tries to convert an object to time value.

:::CodeblockTabs
Tengo

```go
v := time(1257894000) // 2009-11-10 23:00:00 +0000 UTC
```
:::

### is\_string

Returns `true` if the object's type is string. Or it returns `false`.

### is\_int

Returns `true` if the object's type is int. Or it returns `false`.

### is\_bool

Returns `true` if the object's type is bool. Or it returns `false`.

### is\_float

Returns `true` if the object's type is float. Or it returns `false`.

### is\_char

Returns `true` if the object's type is char. Or it returns `false`.

### is\_bytes

Returns `true` if the object's type is bytes. Or it returns `false`.

### is\_error

Returns `true` if the object's type is error. Or it returns `false`.

### is\_undefined

Returns `true` if the object's type is undefined. Or it returns `false`.

### is\_function

Returns `true` if the object's type is function or closure. Or it returns `false`. Note that `is_function` returns `false` for builtin functions and user-provided callable objects.

### is\_callable

Returns `true` if the object is callable (e.g. function, closure, builtin function, or user-provided callable objects). Or it returns `false`.

### is\_array

Returns `true` if the object's type is array. Or it returns `false`.

### is\_immutable\_array

Returns `true` if the object's type is immutable array. Or it returns `false`.

### is\_map

Returns `true` if the object's type is map. Or it returns `false`.

### is\_immutable\_map

Returns `true` if the object's type is immutable map. Or it returns `false`.

### is\_iterable

Returns `true` if the object's type is iterable: array, immutable array, map, immutable map, string, bytes and undefined are iterable types in Tengo.

### range

Returns an int array of the numbers from `start` up to but not including `stop`, stepping by `step` (default 1). All arguments must be ints and `step` must be greater than 0. A range of more than 10,000,000 elements fails with `exceeding range size limit`.

:::CodeblockTabs
Tengo

```go
range(0, 5)      // [0, 1, 2, 3, 4]
range(0, 10, 3)  // [0, 3, 6, 9]
```
:::

:::hint{type="warning"}
Do not use `range` to walk an array by index: it builds the whole int array in memory first. Use `for i := 0; i < len(a); i++` or `for v in a` instead.
:::

### is\_time

Returns `true` if the object's type is time. Or it returns `false`.
