Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > fr.comp.lang.javascript > #3353

Re: Indexation des tableaux en js

From Olivier Miakinen <om+news@miakinen.net>
Newsgroups fr.comp.lang.javascript
Subject Re: Indexation des tableaux en js
Date 2024-11-10 12:22 +0100
Organization There's no cabale
Message-ID <vgq529$2e02$1@cabale.usenet-fr.net> (permalink)
References (8 earlier) <vgngar$3oc57$2@dont-email.me> <vgnium$197m$1@cabale.usenet-fr.net> <6730844c$0$424$426a74cc@news.free.fr> <vgq1vu$2cnv$1@cabale.usenet-fr.net> <vgq2nc$2d19$1@cabale.usenet-fr.net>

Show all headers | View raw


Le 10/11/2024 11:42, je mé répondais :
> 
> Bon, je me suis laissé avoir par l'affichage sur <https://runjs.app/play>.

Non, en réalité cet affichage était correct.

> En réalité, tout index, qu'il soit fourni sous forme de nombre ou sous toute
> autre forme, par exemple une chaine de caractères :
> − est transformé en nombre s'il peut représenter un nombre entre 0 et 2^32-2 ;
> − est transformé en chaine de caractères dans tous les autres cas.

La réalité d'après la norme ECMAScript :


<https://tc39.es/ecma262/#sec-array-objects>
<cit.>
23.1 Array Objects

Arrays are exotic objects that give special treatment to a certain class of
property names. See 10.4.2 for a definition of this special treatment.
</cit.>


<https://tc39.es/ecma262/#sec-array-exotic-objects>
<cit.>
10.4.2 Array Exotic Objects

An Array is an exotic object that gives special treatment to array index
property keys (see 6.1.7). A property whose property name is an array index is
also called an element. [...]

An object is an Array exotic object (or simply, an Array) if its
[[DefineOwnProperty]] internal method uses the following implementation, and its
other essential internal methods use the definitions found in 10.1. These
methods are installed in ArrayCreate.
</cit.>


<https://tc39.es/ecma262/#sec-object-type>
<cit.>
6.1.7 The Object Type

[...]
The properties of an object are uniquely identified using property keys. A
property key is either a String or a Symbol. All Strings and Symbols, including
the empty String, are valid as property keys. A property name is a property key
that is a String.

An integer index is a property name n such that CanonicalNumericIndexString(n)
returns an integral Number in the inclusive interval from +0𝔽 to 𝔽(2**53 - 1).
An array index is an integer index n such that CanonicalNumericIndexString(n)
returns an integral Number in the inclusive interval from +0𝔽 to 𝔽(2**32 - 2).
</cit.>


Ce que je comprends de tout ça, c'est qu'un Array est un objet « exotique »,
et que comme tous ces types d'objets il a des propriétés dont le nom est soit
un symbole (par exemple « null » ou « true »), soit une chaîne de caractères.

J'en comprends aussi qu'il peut avoir au maximum 2^53 propriétés, mais que si
l'une de ces propriétés a comme nom une chaine de caractères représentant un
nombre entier entre 0 et 2^32-2, alors elle est considérée comme un index
numérique et bénéficie alors d'un traitement particulier, comme s'il s'agissait
vraiment d'un tableau indexé par des entiers. Et si par exemple on a un index
égal à 1 000 000 alors c'est comme si on avait vraiment réservé une taille
mémoire de 1 000 001 objets dont les premiers emplacements sont vides.

-- 
Olivier Miakinen

Back to fr.comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Indexation des tableaux en js (was: Re: Le calcul de la racine carré... pour des nuls :)) Thomas Alexandre <none@no.invalid> - 2024-11-10 10:00 +0000
  Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-11-10 11:30 +0100
    Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-11-10 11:42 +0100
      Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-11-10 12:22 +0100
        Re: Indexation des tableaux en js Thomas Alexandre <none@no.invalid> - 2024-11-10 12:50 +0000
          Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-11-10 22:27 +0100
      Re: Indexation des tableaux en js loiseauthierry@free.fr (Thierry Loiseau) - 2024-12-11 20:33 +0100
        Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-12-12 14:42 +0100
          Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-12-12 22:41 +0100
            Re: Indexation des tableaux en js Thomas Alexandre <none@no.invalid> - 2024-12-13 00:07 +0000
              Re: Indexation des tableaux en js Olivier Miakinen <om+news@miakinen.net> - 2024-12-13 19:44 +0100
  Re: Indexation des tableaux en js Samuel Devulder <samuel.devulder@laposte.net.inalid> - 2024-11-10 20:15 +0100
  Re: Indexation des tableaux en js (was: Re: Le calcul de la racine carré... pour des nuls :)) Jo Engo <yl@icite.fr> - 2024-11-30 17:52 +0000
    Re: Indexation des tableaux en js (was: Re: Le calcul de la racine carré... pour des nuls :)) Thomas Alexandre <none@no.invalid> - 2024-12-09 15:29 +0000
      Re: Indexation des tableaux en js Jo Engo <yl@icite.fr> - 2024-12-09 16:51 +0000
        Re: Indexation des tableaux en js Thomas Alexandre <none@no.invalid> - 2024-12-12 11:53 +0000
          Re: Indexation des tableaux en js Jo Engo <yl@icite.fr> - 2024-12-14 18:14 +0000
            Re: Indexation des tableaux en js Thomas Alexandre <none@no.invalid> - 2024-12-16 18:40 +0000
  Re: Indexation des tableaux en js loiseauthierry@free.fr (Thierry Loiseau) - 2024-12-03 08:05 +0100
    Re: Indexation des tableaux en js Thomas Alexandre <none@no.invalid> - 2024-12-09 15:43 +0000

csiph-web