From 95aca4b4d8fa62815d4bd412fff1a364f842814a Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Thu, 29 Apr 2021 16:16:42 -0700 Subject: remove retired locales (#699) --- .../global_objects/object/keys/index.html | 189 --------------------- 1 file changed, 189 deletions(-) delete mode 100644 files/ca/web/javascript/reference/global_objects/object/keys/index.html (limited to 'files/ca/web/javascript/reference/global_objects/object/keys') diff --git a/files/ca/web/javascript/reference/global_objects/object/keys/index.html b/files/ca/web/javascript/reference/global_objects/object/keys/index.html deleted file mode 100644 index 17d05b181c..0000000000 --- a/files/ca/web/javascript/reference/global_objects/object/keys/index.html +++ /dev/null @@ -1,189 +0,0 @@ ---- -title: Object.keys() -slug: Web/JavaScript/Reference/Global_Objects/Object/keys -translation_of: Web/JavaScript/Reference/Global_Objects/Object/keys ---- -
{{JSRef}}
- -

El mètode Object.keys() retorna un array de les propietats enumerables pròpies de l'objecte, en el mateix ordre en que es donarien en un bucle {{jsxref("Statements/for...in", "for...in")}} (la diferència radica en que el bucle for-in també enumera les propietats que pertanyen a la cadena de prototipus).

- -

Sintaxi

- -
Object.keys(obj)
- -

Paràmetres

- -
-
obj
-
L'objecte del qual es retornaran les seves propietats pròpies enumerables.
-
- -

Descripció

- -

Object.keys() retorna un array els elements del qual són strings que corresponen a les propietats enumerables que pertanyen directament a l'objecte obj. L'ordre de les propietats és el mateix que el donat per recòrrer les propieats de l'objecte de forma manual.

- -

Exemples

- -
var arr = ['a', 'b', 'c'];
-console.log(Object.keys(arr)); // console: ['0', '1', '2']
-
-// objecte en forma d'array
-var obj = { 0: 'a', 1: 'b', 2: 'c' };
-console.log(Object.keys(obj)); // console: ['0', '1', '2']
-
-// objecte en forma d'array amb les claus ordenades de manera aleatòria
-var an_obj = { 100: 'a', 2: 'b', 7: 'c' };
-console.log(Object.keys(an_obj)); // console: ['2', '7', '100']
-
-// getFoo és una propietat no enumerable
-var my_obj = Object.create({}, { getFoo: { value: function() { return this.foo; } } });
-my_obj.foo = 1;
-
-console.log(Object.keys(my_obj)); // console: ['foo']
-
- -

Si esteu interessats en obtenir totes les propietats, no només les enumerables, vegeu {{jsxref("Object.getOwnPropertyNames()")}}.

- -

Notes

- -

A l'EcmaScript 5 llençarà una excepció TypeError si el paràmetre obj no és un objecte. A l'EcmaScript 6 el paràmetre serà forçat al tipus Object.

- -
Object.keys("foo");
-// TypeError: "foo" no és un objecte (codi EcmaScript 5)
-Object.keys("foo");
-// ["0", "1", "2"]                   (codi EcmaScript 6)
-
- -

Polyfill

- -

Per a afegit una funció compatible amb Object.keys en plataformes que no la suporten de forma nativa, podeu utilitzar el codi següent:

- -
// Tret de https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys
-if (!Object.keys) {
-  Object.keys = (function() {
-    'use strict';
-    var hasOwnProperty = Object.prototype.hasOwnProperty,
-        hasDontEnumBug = !({ toString: null }).propertyIsEnumerable('toString'),
-        dontEnums = [
-          'toString',
-          'toLocaleString',
-          'valueOf',
-          'hasOwnProperty',
-          'isPrototypeOf',
-          'propertyIsEnumerable',
-          'constructor'
-        ],
-        dontEnumsLength = dontEnums.length;
-
-    return function(obj) {
-      if (typeof obj !== 'object' && (typeof obj !== 'function' || obj === null)) {
-        throw new TypeError('Object.keys called on non-object');
-      }
-
-      var result = [], prop, i;
-
-      for (prop in obj) {
-        if (hasOwnProperty.call(obj, prop)) {
-          result.push(prop);
-        }
-      }
-
-      if (hasDontEnumBug) {
-        for (i = 0; i < dontEnumsLength; i++) {
-          if (hasOwnProperty.call(obj, dontEnums[i])) {
-            result.push(dontEnums[i]);
-          }
-        }
-      }
-      return result;
-    };
-  }());
-}
-
- -

Cal destacar que aquest codi inclou també propietats no enumerables a Internet Explorer 7 (i possiblement també a Internet Explorer 8), al passar un objecte pertanyent a una altra finestra.

- -

Per a una versió simplificada Polyfill per a navegadors vegeu Compatibilitat de navegadors amb la funció Object.keys de JavaScript.

- -

Especificacions

- - - - - - - - - - - - - - - - - - - -
EspecificacióEstatComentaris
{{SpecName('ES5.1', '#sec-15.2.3.14', 'Object.keys')}}{{Spec2('ES5.1')}}Definició inicial. Implementat a 1.8.5.
{{SpecName('ES6', '#sec-object.keys', 'Object.keys')}}{{Spec2('ES6')}} 
- -

Compatibilitat amb navegadors

- -
{{CompatibilityTable}}
- -
- - - - - - - - - - - - - - - - - - - -
CaracterísticaChromeFirefox (Gecko)Internet ExplorerOperaSafari
Suport bàsic{{CompatChrome("5")}}{{CompatGeckoDesktop("2.0")}}{{CompatIE("9")}}{{CompatOpera("12")}}{{CompatSafari("5")}}
-
- -
- - - - - - - - - - - - - - - - - - - - - -
CaracterísticaAndroidChrome for AndroidFirefox Mobile (Gecko)IE MobileOpera MobileSafari Mobile
Suport bàsic{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}{{CompatUnknown}}
-
- -

Vegeu també

- - -- cgit v1.2.3-54-g00ecf