Object

O construtor Object cria um wrapper de objeto.

Sintaxe

// Object initialiser or literal
{ [ nameValuePair1[, nameValuePair2[, ...nameValuePairN] ] ] }

// Called as a constructor
new Object([value])

Parametros

nameValuePair1, nameValuePair2, ... nameValuePairN
Pares de nomes (strings) e valores (qualquer valor) em que o nome é separado do valor por dois pontos.
value
Qualquer valor.

Descrição

O construtor Object cria um wrapper de objeto para o valor fornecido. Se o valor for null ou undefined, ele criará e retornará um objeto vazio, caso contrário, retornará um objeto de um Type que corresponde ao dado valor. Se o valor já for um objeto, ele retornará o valor.

Quando chamado em um contexto não-construtor, o object se comporta de forma idêntica ao new Object ().

Veja também object initializer / literal syntax.

Propriedades do construtor Object

Object.length
Tem um valor de 1.
Object.prototype
Permite a adição de propriedades a todos os objetos do tipo Object.

Métodos do construtor Object

Object.assign()
Copia os valores de todas as propriedades próprias enumeráveis ​​de um ou mais objetos de origem para um objeto de destino.
Object.create()
Cria um novo objeto com o objeto e as propriedades do protótipo especificado.
Object.defineProperty()
Adiciona a propriedade nomeada descrita por um determinado descritor a um objeto.
Object.defineProperties()
Adiciona as propriedades nomeadas descritas pelos descritores fornecidos a um objeto.
Object.entries()
Retorna uma matriz contendo todos os pares [key, value] das próprias propriedades de string enumeráveis ​​de um determinado objeto.
Object.freeze()
Congela um objeto: outro código não pode excluir ou alterar nenhuma propriedade.
Object.fromEntries()
Retorna um novo objeto de um iterável de pares de valor-chave (reverso à Object.entries).
Object.getOwnPropertyDescriptor()
Retorna um descritor de propriedade para uma propriedade nomeada em um objeto.
Object.getOwnPropertyDescriptors()
Retorna um objeto contendo todos os descritores de propriedade para um objeto.
Object.getOwnPropertyNames()
Retorna uma matriz contendo os nomes de todas as propriedades enumeráveis ​​e não enumeráveis ​​do próprio objeto fornecido.
Object.getOwnPropertySymbols()
Retorna uma matriz de todas as propriedades de símbolo encontradas diretamente sobre um determinado objeto.
Object.getPrototypeOf()
Retorna o protótipo do objeto especificado.
Object.is()
Compara se dois valores são o mesmo valor. Equivale a todos os valores de NaN (que diferem da Comparação de Igualdade Abstrata e da Comparação de Igualdade Estrita).
Object.isExtensible()
Determina se a extensão de um objeto é permitida.
Object.isFrozen()
Determina se um objeto foi congelado.
Object.isSealed()
Determina se um objeto está selado.
Object.keys()
Retorna uma matriz contendo os nomes de todas as propriedades de string enumeráveis ​​do objeto fornecido.
Object.preventExtensions()
Impede qualquer extensão de um objeto.
Object.seal()
Impede que outro código exclua propriedades de um objeto.
Object.setPrototypeOf()
Define o protótipo (isto é, a propriedade interna [[Prototype]]).
Object.values()
Retorna uma matriz contendo os valores que correspondem a todas as propriedades de string enumeráveis ​​do próprio objeto.

Instâncias de Object e Object de protótipo de objeto

Todos os objetos em JavaScript são descendentes do Object; todos os objetos herdam métodos e propriedades de Object.prototype, embora eles possam ser substituídos. Por exemplo, protótipos de outros construtores substituem a propriedade constructor e fornecer seus próprios métodos toString(). As alterações no objeto de protótipo Object são propagadas para todos os objetos, a menos que as propriedades e os métodos sujeitos a essas alterações sejam substituídos na cadeia de protótipos.

Propriedades (enUS)

Métodos (enUS)

Excluindo uma propriedade de um objeto

Não há nenhum método em um Objeto para excluir suas próprias propriedades (por exemplo, como Map.prototype.delete()). Para isso, é necessário usar o operador delete.

Exemplos

Usando Object com tipos undefinednull

Os exemplos a seguir armazenam um Object vazio na variável "o":

var o = new Object();
var o = new Object(undefined);
var o = new Object(null);

Using Object to create Boolean objects

Os exemplos a seguir armazenam objetos Boolean na variável "o":

// equivalent to o = new Boolean(true);
var o = new Object(true);
// equivalent to o = new Boolean(false);
var o = new Object(Boolean());

Especificações

Especificações Status Comentário
ECMAScript 1st Edition (ECMA-262) Padrão Definição inicial. Implementado no JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Object' in that specification.
Padrão ------------------------------------------------
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Object' in that specification.
Padrão Adicionado Object.assign, Object.getOwnPropertySymbols, Object.setPrototypeOf e Object.is
ECMAScript (ECMA-262)
The definition of 'Object' in that specification.
Padrão em tempo real Adicionado  Object.entries, Object.values e Object.getOwnPropertyDescriptors.

Compatibilidade

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
ObjectChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
Object() constructorChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
assignChrome Full support 45Edge Full support 12Firefox Full support 34IE No support NoOpera Full support 32Safari Full support 9WebView Android Full support 45Chrome Android Full support 45Firefox Android Full support 34Opera Android Full support 32Safari iOS Full support 9Samsung Internet Android Full support 5.0nodejs Full support 4.0.0
constructorChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
createChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 11.6Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
__defineGetter__
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1
Notes
Full support 1
Notes
Notes Starting with Firefox 48, this method can no longer be called at the global scope without any object. A TypeError will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
IE Full support 11Opera Full support 9.5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
definePropertiesChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 11.6Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
definePropertyChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9
Full support 9
Partial support 8
Notes
Notes In Internet Explorer 8, this was only supported on DOM objects and with some non-standard behaviors. This was later fixed in Internet Explorer 9.
Opera Full support 11.6Safari Full support 5.1
Notes
Full support 5.1
Notes
Notes Also supported in Safari 5, but not on DOM objects.
WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6
Notes
Full support 6
Notes
Notes Also supported in Safari for iOS 4.2, but not on DOM objects.
Samsung Internet Android Full support 1.0nodejs Full support Yes
__defineSetter__
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1
Notes
Full support 1
Notes
Notes Starting with Firefox 48, this method can no longer be called at the global scope without any object. A TypeError will be thrown otherwise. Previously, the global object was used in these cases automatically, but this is no longer the case.
IE Full support 11Opera Full support 9.5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
entriesChrome Full support 54Edge Full support 14Firefox Full support 47IE No support NoOpera Full support 41Safari Full support 10.1WebView Android Full support 54Chrome Android Full support 54Firefox Android Full support 47Opera Android Full support 41Safari iOS Full support 10.3Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.
freezeChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
fromEntriesChrome Full support 73Edge Full support 79Firefox Full support 63IE No support NoOpera Full support 60Safari Full support 12.1WebView Android Full support 73Chrome Android Full support 73Firefox Android Full support 63Opera Android No support NoSafari iOS Full support 12.2Samsung Internet Android No support Nonodejs Full support 12.0.0
getOwnPropertyDescriptorChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9
Full support 9
Partial support 8
Notes
Notes In Internet Explorer 8, this was only supported on DOM objects and with some non-standard behaviors. This was later fixed in Internet Explorer 9.
Opera Full support 12Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
getOwnPropertyDescriptorsChrome Full support 54Edge Full support 15Firefox Full support 50IE No support NoOpera Full support 41Safari Full support 10WebView Android Full support 54Chrome Android Full support 54Firefox Android Full support 50Opera Android Full support 41Safari iOS Full support 10Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.
getOwnPropertyNamesChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
getOwnPropertySymbolsChrome Full support 38Edge Full support 12Firefox Full support 36IE No support NoOpera Full support 25Safari Full support 9WebView Android Full support 38Chrome Android Full support 38Firefox Android Full support 36Opera Android Full support 25Safari iOS Full support 9Samsung Internet Android Full support 3.0nodejs Full support 0.12
getPrototypeOfChrome Full support 5Edge Full support 12Firefox Full support 3.5IE Full support 9Opera Full support 12.1Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12.1Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
hasOwnPropertyChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support 5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
isChrome Full support 30Edge Full support 12Firefox Full support 22IE No support NoOpera Full support 17Safari Full support 9WebView Android Full support ≤37Chrome Android Full support 30Firefox Android Full support 22Opera Android Full support 18Safari iOS Full support 9Samsung Internet Android Full support 2.0nodejs Full support 0.10
isExtensibleChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
isFrozenChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
isPrototypeOfChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 9Opera Full support 4Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
isSealedChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
keysChrome Full support 5Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 5Samsung Internet Android Full support 1.0nodejs Full support Yes
__lookupGetter__
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 11Opera Full support 9.5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
__lookupSetter__
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 11Opera Full support 9.5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
preventExtensionsChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
propertyIsEnumerableChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support 4Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
__proto__
Deprecated
Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 11Opera Full support 10.5Safari Full support 3WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 11Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
sealChrome Full support 6Edge Full support 12Firefox Full support 4IE Full support 9Opera Full support 12Safari Full support 5.1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 12Safari iOS Full support 6Samsung Internet Android Full support 1.0nodejs Full support Yes
setPrototypeOfChrome Full support 34Edge Full support 12Firefox Full support 31IE Full support 11Opera Full support 21Safari Full support 9WebView Android Full support 37Chrome Android Full support 34Firefox Android Full support 31Opera Android Full support 21Safari iOS Full support 9Samsung Internet Android Full support 2.0nodejs Full support 0.12
toLocaleStringChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support 4Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
toSource
DeprecatedNon-standard
Chrome No support NoEdge No support NoFirefox No support 1 — 74
Notes
No support 1 — 74
Notes
Notes Starting in Firefox 74, toSource() is no longer available for use by web content. It is still allowed for internal and privileged code.
IE No support NoOpera No support NoSafari No support NoWebView Android No support NoChrome Android No support NoFirefox Android Full support 4Opera Android No support NoSafari iOS No support NoSamsung Internet Android No support Nonodejs No support No
toString()Chrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
valueOfChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support 3Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support 10.1Safari iOS Full support 1Samsung Internet Android Full support 1.0nodejs Full support Yes
valuesChrome Full support 54Edge Full support 14Firefox Full support 47IE No support NoOpera Full support 41Safari Full support 10.1WebView Android Full support 54Chrome Android Full support 54Firefox Android Full support 47Opera Android Full support 41Safari iOS Full support 10.3Samsung Internet Android Full support 6.0nodejs Full support 7.0.0
Full support 7.0.0
Full support 6.5.0
Disabled
Disabled From version 6.5.0: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
No support  
No support
Non-standard. Expect poor cross-browser support.
Non-standard. Expect poor cross-browser support.
Deprecated. Not for use in new websites.
Deprecated. Not for use in new websites.
See implementation notes.
See implementation notes.
User must explicitly enable this feature.
User must explicitly enable this feature.

Veja também