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


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

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 11:42 +0100
Organization There's no cabale
Message-ID <vgq2nc$2d19$1@cabale.usenet-fr.net> (permalink)
References (7 earlier) <672ea1f1$0$16817$426a34cc@news.free.fr> <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>

Show all headers | View raw


Le 10/11/2024 11:30, j'écrivais :
> 
> Cela confirme ce que je disais pour les nombres. Mais je vois que null, true,
> false et NaN ne sont pas transformés. C'est encore plus drôle avec +∞ et −∞
> car seul le second est transformé en chaine de caractères.
> 
> a[4294967294] = 4294967294
> a[4294967295] = 4294967295
> a[true] = 1
> a[null] = 0
> a[false] = -1
> a[NaN] = 42
> a[1/0] = 1/0
> a[-1/0] = -1/0
> 
> Résultat :
> [ <4294967294 empty items>, 4294967294, '4294967295': 4294967295, true: 1, null:
> 0, false: -1, NaN: 42, Infinity: Infinity, '-Infinity': -Infinity ]

Bon, je me suis laissé avoir par l'affichage sur <https://runjs.app/play>.

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 preuve :

a[0] = 0
a['0'] = '0'
a[4294967294] = 4294967294
a['4294967294'] = '4294967294'
a[true] = 1
a['true'] = 'true'
a[null] = 0
a['null'] = 'null'
a[false] = -1
a['false'] = 'false'
a[NaN] = 42
a['NaN'] = 'NaN'
a[1/0] = 1/0
a['Infinity'] = '+∞'
a[-1/0] = -1/0
a['-Infinity'] = '−∞'

Résultat :
[ '0', <4294967293 empty items>, '4294967294', \\ nombres entre 0 et 4294967294
  true: 'true', null: 'null', false: 'false', NaN: 'NaN', \\ autres
  Infinity: '+∞', '-Infinity': '−∞' ] \\ autres

-- 
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