# Object

## Overview

The Object type is used to store various keyed collections and more complex entities.\
Nearly all objects in JavaScript are instances of Object.

For more information see: [Object (MDN)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object).

## Methods Summarized

| Type                                                                           | Name                                                                                       | Summary                                                                                                                                                                                                                                     |
| ------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [assign(target, sources)](#assign-target-sources)                                          | Copy the values of all enumerable own properties from one or more source objects to a target object.                                                                                                                                        |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [create(object)](#create-object)                                                           | Creates a new object, using an existing object to provide the newly created object's prototype.                                                                                                                                             |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [create(object, properties)](#create-object-properties)                                    | Creates a new object, using an existing object to provide the newly created object's prototype and properties.                                                                                                                              |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [defineProperties(object, properties)](#defineproperties-object-properties)                | Defines new or modifies existing properties directly on an object, returning the object.                                                                                                                                                    |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [defineProperty(object, property, descriptor)](#defineproperty-object-property-descriptor) | Allows a precise addition to or modification of a property on an object.                                                                                                                                                                    |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [entries(object1)](#entries-object1)                                                       | Returns an array whose elements are arrays corresponding to the enumerable string-keyed property key-value pairs found directly upon object.                                                                                                |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [freeze(object)](#freeze-object)                                                           | Freezes an object: that is, prevents new properties from being added to it; prevents existing properties from being removed; and prevents existing properties, or their enumerability, configurability, or writability, from being changed. |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [fromEntries(entries)](#fromentries-entries)                                               | Transforms a list of key-value pairs into an object                                                                                                                                                                                         |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [getOwnPropertyDescriptor(object, property)](#getownpropertydescriptor-object-property)    | Permits examination of the precise description of a property.                                                                                                                                                                               |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [getOwnPropertyNames(object)](#getownpropertynames-object)                                 | Returns an array of all properties (including non-enumerable properties) found directly upon a given object.                                                                                                                                |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [getPrototypeOf(object)](#getprototypeof-object)                                           | Returns the prototype of the specified object.                                                                                                                                                                                              |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [hasOwnProperty(prop)](#hasownproperty-prop)                                               | Determine whether the object has the specified property as its own property (as opposed to inheriting it).                                                                                                                                  |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [is(value1, value2)](#is-value1-value2)                                                    | Determines whether two values are the same value.                                                                                                                                                                                           |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isExtensible(object)](#isextensible-object)                                               | Determines if an object is extensible (whether it can have new properties added to it).                                                                                                                                                     |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isFrozen(object)](#isfrozen-object)                                                       | Determines if an object is frozen.                                                                                                                                                                                                          |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isPrototypeOf(object)](#isprototypeof-object)                                             | Checks if an object exists in another object's prototype chain.                                                                                                                                                                             |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [isSealed(object)](#issealed-object)                                                       | Determines if an object is sealed.                                                                                                                                                                                                          |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [keys(object)](#keys-object)                                                               | Returns an array of all own enumerable properties found upon a given object, in the same order as that provided by a for-in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).            |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [preventExtensions(object)](#preventextensions-object)                                     | Prevents new properties from ever being added to an object (i.                                                                                                                                                                              |
| [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) | [propertyIsEnumerable(prop)](#propertyisenumerable-prop)                                   | Indicates whether the specified property is enumerable.                                                                                                                                                                                     |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [seal(object)](#seal-object)                                                               | Seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable.                                                                                                                  |
| void                                                                           | [setPrototypeOf(obj, prototype)](#setprototypeof-obj-prototype)                            | Sets the prototype of a specified object to another object or null.                                                                                                                                                                         |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [toLocaleString()](#tolocalestring)                                                        | Returns a string representing the object.                                                                                                                                                                                                   |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)   | [toString()](#tostring)                                                                    | Returns a string representing the specified object.                                                                                                                                                                                         |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)   | [valueOf()](#valueof)                                                                      | Returns the primitive value of the specified object.                                                                                                                                                                                        |
| [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array)     | [values(object1)](#values-object1)                                                         | Returns an array whose elements are strings corresponding to the enumerable string-keyed property values found directly upon object.                                                                                                        |

## Methods Detailed

### assign(target, sources)

Copy the values of all enumerable own properties from one or more source objects to a target object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **target** The target object.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **sources** The source object(s).

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The target object.

**Sample**

```js
var object1 = { a: 1, b: 2, c: 3};
var object2 = Object.assign({c: 4, d: 5}, object1);
application.output(object2.c, object2.d);
```

### create(object)

Creates a new object, using an existing object to provide the newly created object's prototype.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be the prototype of the newly-created object.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) A new object with the specified prototype object.

**Sample**

```js
const person = {
	isHuman: false,
	printIntroduction: function () {
		application.output("My name is " + this.name + ". Am I human? " + this.isHuman);
	}
};
var me = Object.create(person);
me.name = "Matthew"; // "name" is a property set on "me", but not on "person"
me.isHuman = true; // inherited properties can be overwritten
me.printIntroduction(); // expected output: "My name is Matthew. Am I human? true"
```

### create(object, properties)

Creates a new object, using an existing object to provide the newly created object's prototype and properties.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be the prototype of the newly-created object.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **properties** ;

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) A new object with the specified prototype object.

**Sample**

```js
var o = Object.create({}, { p: { value: 42 } });
application.output(o.p);
```

### defineProperties(object, properties)

Defines new or modifies existing properties directly on an object, returning the object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object on which to define or modify properties.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **properties** An object whose own enumerable properties constitute descriptors for the properties to be defined or modified.\
  &#x20;           Descriptors have the following keys:\
  &#x20;           configurable - true if and only if the type of this property descriptor may be changed and if the property may be deleted\
  &#x20;                           from the corresponding object. Defaults to false.\
  &#x20;           enumerable - true if and only if this property shows up during enumeration of the properties on the corresponding object.\
  &#x20;                           Defaults to false.\
  &#x20;           value - The value associated with the property. Can be any valid JavaScript value (number, object, function, etc).\
  &#x20;                           Defaults to undefined.\
  &#x20;           writable - true if and only if the value associated with the property may be changed with an assignment operator.\
  &#x20;                           Defaults to false.\
  &#x20;           get - A function which serves as a getter for the property, or undefined if there is no getter. The function return will\
  &#x20;                 be used as the value of property. Defaults to undefined.\
  &#x20;           set - A function which serves as a setter for the property, or undefined if there is no setter. The function will receive\
  &#x20;                 as only argument the new value being assigned to the property. Defaults to undefined.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The object that was passed to the function.

**Sample**

```js
const object1 = {};
Object.defineProperties(object1, {property1: {value: 42, writable: true},   property2: {}});
application.output(object1.property1);
```

### defineProperty(object, property, descriptor)

Allows a precise addition to or modification of a property on an object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object on which to define or modify properties.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **property** The name of the property to be defined or modified.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **descriptor** The descriptor for the property being defined or modified.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The object that was passed to the function.

**Sample**

```js
const object1 = {};
Object.defineProperty(object1, 'property1', {value: 42, writable: false});
application.output(object1.property1);
```

### entries(object1)

Returns an array whose elements are arrays corresponding to the enumerable string-keyed property key-value pairs found directly upon object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object1** An object.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) An array of the given object's own enumerable string-keyed property key-value pairs. Each key-value pair is an array with two elements: the first element is the property key (which is always a string), and the second element is the property value.

**Sample**

```js
const object1 = { a: 'somestring',  b: 42,  c: false};
application.output(Object.entries(object1));
```

### freeze(object)

Freezes an object: that is, prevents new properties from being added to it; prevents existing properties from being removed; and prevents existing properties, or their enumerability, configurability, or writability, from being changed. In essence the object is made effectively immutable.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object to freeze.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The object that was passed to the function.

**Sample**

```js
const object1 = { property1: 42 };
const object2 = Object.freeze(object1);
object2.property1 = 33;
application.output(object2.property1); //expected result is 42
```

### fromEntries(entries)

Transforms a list of key-value pairs into an object

**Parameters**

* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **entries** A list of objects. Each object is an array with two values, first value is the key second one is the value.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) A new object whose properties are given by the entries of the array.

**Sample**

```js
application.output(Object.fromEntries(entries));
```

### getOwnPropertyDescriptor(object, property)

Permits examination of the precise description of a property.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object in which to look for the property.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **property** The name of the property whose description is to be retrieved.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) A property descriptor of the given property if it exists on the object, undefined otherwise.

**Sample**

```js
const object1 = { property1: 42 };
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
application.output(descriptor1.configurable); // expected output: true
application.output(descriptor1.value); //expected result is 42
```

### getOwnPropertyNames(object)

Returns an array of all properties (including non-enumerable properties) found directly upon a given object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object whose enumerable and non-enumerable own properties are to be returned.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) An array of strings that correspond to the properties found directly upon the given object.

**Sample**

```js
const object1 = { a: 1, b: 2, c: 3};
application.output(Object.getOwnPropertyNames(object1));
```

### getPrototypeOf(object)

Returns the prototype of the specified object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object whose prototype is to be returned.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The prototype of the given object. If there are no inherited properties, null is returned.

**Sample**

```js
const prototype1 = {};
const object1 = Object.create(prototype1);
application.output(Object.getPrototypeOf(object1) === prototype1); // expected output: true
```

### hasOwnProperty(prop)

Determine whether the object has the specified property as its own property (as opposed to inheriting it).

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **prop** The name of the property to test.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether or not the object has the specified property as own property.

**Sample**

```js
const object1 = new Object();
 object1.property1 = 42;
 application.output(object1.hasOwnProperty('property1')); // expected output: true
 application.output(object1.hasOwnProperty('toString')); // expected output: false
 application.output(object1.hasOwnProperty('hasOwnProperty')); // expected output: false
```

### is(value1, value2)

Determines whether two values are the same value.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value1** The first value to compare.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value2** The second value to compare.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) a Boolean indicating whether or not the two arguments are the same value.

**Sample**

```js
Object.is('foo', 'foo');
```

### isExtensible(object)

Determines if an object is extensible (whether it can have new properties added to it).\
Objects are extensible by default, can be marked as non-extensible using Object.preventExtensions(), Object.seal(), or Object.freeze().

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be checked.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether or not the given object is extensible.

**Sample**

```js
var empty = {};
Object.isExtensible(empty); // === true

Object.preventExtensions(empty);
Object.isExtensible(empty); // === false

var sealed = Object.seal({});
Object.isExtensible(sealed); // === false

var frozen = Object.freeze({});
Object.isExtensible(frozen); // === false
```

### isFrozen(object)

Determines if an object is frozen. An object is frozen if and only if it is not extensible, all its properties are non-configurable, and all its data properties (that is, properties which are not accessor properties with getter or setter components) are non-writable.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be checked.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether or not the given object is frozen.

**Sample**

```js
const object1 = { property1: 42 };
application.output(Object.isFrozen(object1)); // expected output: false
Object.freeze(object1);
application.output(Object.isFrozen(object1)); // expected output: true
```

### isPrototypeOf(object)

Checks if an object exists in another object's prototype chain.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object whose prototype chain will be searched.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether the calling object lies in the prototype chain of the specified object.

**Sample**

```js
function object1() {}
function object2() {}
object1.prototype = Object.create(object2.prototype);
const object3 = new object1();
application.output(object1.prototype.isPrototypeOf(object3)); // expected output: true
application.output(object2.prototype.isPrototypeOf(object3)); // expected output: true
```

### isSealed(object)

Determines if an object is sealed. An object is sealed if it is not extensible and if all its properties are non-configurable and therefore not removable (but not necessarily non-writable).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be checked.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether or not the given object is sealed.

**Sample**

```js
const object1 = { property1: 42 };
application.output(Object.isSealed(object1)); // expected output: false
Object.seal(object1);
application.output(Object.isSealed(object1)); // expected output: true
```

### keys(object)

Returns an array of all own enumerable properties found upon a given object, in the same order as that provided by a for-in loop (the difference being that a for-in loop enumerates properties in the prototype chain as well).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** An array of strings that represent all the enumerable properties of the given object.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) The object of which the enumerable's own properties are to be returned.

**Sample**

```js
const object1 = {a: 'somestring', b: 42, c: false };
application.outout(Object.keys(object1)); // expected output: Array ["a", "b", "c"]
```

### preventExtensions(object)

Prevents new properties from ever being added to an object (i.e. prevents future extensions to the object).

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be made non-extensible.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The object being made non-extensible.

**Sample**

```js
const object1 = {};
Object.preventExtensions(object1);
try {
  Object.defineProperty(object1, 'property1', {
      value: 42
 });
 } catch (e) {
   application.output(e);
}
```

### propertyIsEnumerable(prop)

Indicates whether the specified property is enumerable.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **prop** The name or symbol of the property to test.

**Returns:** [Boolean](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/boolean) A Boolean indicating whether the specified property is enumerable.

**Sample**

```js
const array1 = [];
object1.property1 = 42;
array1[0] = 42;
application.output(object1.propertyIsEnumerable('property1')); // expected output: true
application.output(array1.propertyIsEnumerable(0)); // expected output: true
application.output(array1.propertyIsEnumerable('length')); // expected output: false
```

### seal(object)

Seals an object, preventing new properties from being added to it and marking all existing properties as non-configurable.\
Values of present properties can still be changed as long as they are writable.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object** The object which should be sealed.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The object being sealed.

**Sample**

```js
const object1 = { property1: 42 };
Object.seal(object1);
object1.property1 = 33;
application.output(object1.property1); // expected output: 33

delete object1.property1; // cannot delete when sealed
application.output(object1.property1); // expected output: 33
```

### setPrototypeOf(obj, prototype)

Sets the prototype of a specified object to another object or null.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **obj** The object which is to have its prototype set.
* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **prototype** The object's new prototype (an object or null).

**Returns:** void

**Sample**

```js
const obj = {};
const parent = { foo: 'bar' };

application.output(obj.foo);
// Expected output: undefined
Object.setPrototypeOf(obj, parent);
application.output(obj.foo);
// Expected output: "bar"
```

### toLocaleString()

Returns a string representing the object. This method is meant to be overriden by derived objects for locale-specific purposes.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) A string representing the object.

**Sample**

```js
const number1 = 123456.789;
application.output(number1.toLocaleString()); // expected output: "123.456,789"
```

### toString()

Returns a string representing the specified object.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) A string representing the object.

**Sample**

```js
function Dog(name) {
  this.name = name;
}
var dog1 = new Dog('Spike');
Dog.prototype.toString = function dogToString() { return this.name; }

application.output(dog1.toString());
```

### valueOf()

Returns the primitive value of the specified object. By default, the valueOf method is inherited by every object descended from Object.\
Every built-in core object overrides this method to return an appropriate value.\
If an object has no primitive value, valueOf returns the object itself.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) The primitive value of the specified object.

**Sample**

```js
function MyNumberType(n) {
 this.number = n;
}
MyNumberType.prototype.valueOf = function() { return this.number; };

const object1 = new MyNumberType(4);
application.output(object1 + 3); // expected output: 7
```

### values(object1)

Returns an array whose elements are strings corresponding to the enumerable string-keyed property values found directly upon object.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **object1** An object.

**Returns:** [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) an array of a given object's own enumerable string-keyed property values.

**Sample**

```js
const object1 = { a: 'somestring',  b: 42,  c: false};
Object.values(object1);
```

***
