# 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](/reference/servoycore/dev-api/js-lib/object.md)   | [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](/reference/servoycore/dev-api/js-lib/object.md)   | [create(object)](#create-object)                                                           | Creates a new object, using an existing object to provide the newly created object's prototype.                                                                                                                                             |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [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](/reference/servoycore/dev-api/js-lib/object.md)   | [defineProperties(object, properties)](#defineproperties-object-properties)                | Defines new or modifies existing properties directly on an object, returning the object.                                                                                                                                                    |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [defineProperty(object, property, descriptor)](#defineproperty-object-property-descriptor) | Allows a precise addition to or modification of a property on an object.                                                                                                                                                                    |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [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](/reference/servoycore/dev-api/js-lib/object.md)   | [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](/reference/servoycore/dev-api/js-lib/object.md)   | [fromEntries(entries)](#fromentries-entries)                                               | Transforms a list of key-value pairs into an object                                                                                                                                                                                         |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [getOwnPropertyDescriptor(object, property)](#getownpropertydescriptor-object-property)    | Permits examination of the precise description of a property.                                                                                                                                                                               |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [getOwnPropertyNames(object)](#getownpropertynames-object)                                 | Returns an array of all properties (including non-enumerable properties) found directly upon a given object.                                                                                                                                |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [getPrototypeOf(object)](#getprototypeof-object)                                           | Returns the prototype of the specified object.                                                                                                                                                                                              |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [hasOwnProperty(prop)](#hasownproperty-prop)                                               | Determine whether the object has the specified property as its own property (as opposed to inheriting it).                                                                                                                                  |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [is(value1, value2)](#is-value1-value2)                                                    | Determines whether two values are the same value.                                                                                                                                                                                           |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [isExtensible(object)](#isextensible-object)                                               | Determines if an object is extensible (whether it can have new properties added to it).                                                                                                                                                     |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [isFrozen(object)](#isfrozen-object)                                                       | Determines if an object is frozen.                                                                                                                                                                                                          |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [isPrototypeOf(object)](#isprototypeof-object)                                             | Checks if an object exists in another object's prototype chain.                                                                                                                                                                             |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [isSealed(object)](#issealed-object)                                                       | Determines if an object is sealed.                                                                                                                                                                                                          |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [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](/reference/servoycore/dev-api/js-lib/object.md)   | [preventExtensions(object)](#preventextensions-object)                                     | Prevents new properties from ever being added to an object (i.                                                                                                                                                                              |
| [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) | [propertyIsEnumerable(prop)](#propertyisenumerable-prop)                                   | Indicates whether the specified property is enumerable.                                                                                                                                                                                     |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [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](/reference/servoycore/dev-api/js-lib/string.md)   | [toLocaleString()](#tolocalestring)                                                        | Returns a string representing the object.                                                                                                                                                                                                   |
| [String](/reference/servoycore/dev-api/js-lib/string.md)   | [toString()](#tostring)                                                                    | Returns a string representing the specified object.                                                                                                                                                                                         |
| [Object](/reference/servoycore/dev-api/js-lib/object.md)   | [valueOf()](#valueof)                                                                      | Returns the primitive value of the specified object.                                                                                                                                                                                        |
| [Array](/reference/servoycore/dev-api/js-lib/array.md)     | [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](/reference/servoycore/dev-api/js-lib/object.md) **target** The target object.
* [Array](/reference/servoycore/dev-api/js-lib/array.md) **sources** The source object(s).

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be the prototype of the newly-created object.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be the prototype of the newly-created object.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **properties** ;

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

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object on which to define or modify properties.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **property** The name of the property to be defined or modified.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **descriptor** The descriptor for the property being defined or modified.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object1** An object.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object to freeze.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/array.md) **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](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object in which to look for the property.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **property** The name of the property whose description is to be retrieved.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object whose enumerable and non-enumerable own properties are to be returned.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object whose prototype is to be returned.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/string.md) **prop** The name of the property to test.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **value1** The first value to compare.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **value2** The second value to compare.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be checked.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be checked.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object whose prototype chain will be searched.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be checked.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** An array of strings that represent all the enumerable properties of the given object.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be made non-extensible.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **prop** The name or symbol of the property to test.

**Returns:** [Boolean](/reference/servoycore/dev-api/js-lib/boolean.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object** The object which should be sealed.

**Returns:** [Object](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **obj** The object which is to have its prototype set.
* [Object](/reference/servoycore/dev-api/js-lib/object.md) **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](/reference/servoycore/dev-api/js-lib/string.md) 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](/reference/servoycore/dev-api/js-lib/string.md) 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](/reference/servoycore/dev-api/js-lib/object.md) 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](/reference/servoycore/dev-api/js-lib/object.md) **object1** An object.

**Returns:** [Array](/reference/servoycore/dev-api/js-lib/array.md) 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);
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
