# Method: $clear()

Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 1 minute(s)

# Description

The $clear() method clears (deletes) all the members (properties) from an object or array leaving the object/array void.

# Syntax

obj->$clear()
arr->$clear()
1
2

# Arguments

None

# Return values

The current object

# Examples

obj = new object
fruit = new array
obj->name = "Mr Healthy"
obj->diet = "mediterranean"
fruit->$append("apples")->$append("oranges")->$append("grapes")
obj->fruit = fruit
crt obj->$tojson()
fruit->$clear()       ;* clears the array
crt obj->$tojson()
crt fruit->$tojson()
crt obj->$clear()->$tojson()   ;* clears and displays the object in JSON format
1
2
3
4
5
6
7
8
9
10
11

Results:

{"name":"Mr Healthy","diet":"mediterranean","fruit":["apples","oranges","grapes"]}
{"name":"Mr Healthy","diet":"mediterranean","fruit":[]}
[]
{}
1
2
3
4

Back to Built-in Methods