Chiavi array JavaScript ()

Il metodo JavaScript Array keys () restituisce un nuovo oggetto Array Iterator che contiene le chiavi per ogni indice dell'array.

La sintassi del keys()metodo è:

 arr.keys()

Qui, arr è un array.

keys () Parametri

Il keys()metodo non ha parametri.

Valore restituito dalle chiavi ()

  • Restituisce un nuovo Arrayoggetto iteratore.

Note :

  • Il keys()metodo non modifica l'array originale.
  • Il keys()metodo non ignora gli elementi dell'array vuoto.

Esempio: utilizzo del metodo keys ()

 const languages = ("JavaScript", "Java", , "C++", "Python"); let iterator = languages.keys(); for (let key of iterator) ( console.log(key); )

Produzione

 0 1 2 3 4

Notare che il terzo elemento vuoto non viene ignorato.

Letture consigliate: valori array JavaScript ()

Articoli interessanti...