Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
arrays.index_to_float
arrays.index_to_float(array, index)
Descrizione
Restituisce l'elemento all'indice specificato di un array. L'elemento in quell'indice viene restituito come numero in virgola mobile.
L'indice è un valore intero che rappresenta la posizione di un elemento nell'array.
Per impostazione predefinita, il primo elemento di un array ha un indice pari a 0 e l'ultimo elemento ha un indice pari a n-1, dove n è la dimensione dell'array.
L'indicizzazione negativa consente di accedere agli elementi dell'array rispetto alla fine dell'array. Ad esempio, un indice di -1 si riferisce all'ultimo elemento dell'array e un indice di -2 si riferisce al penultimo elemento dell'array.
Tipi di dati dei parametri
ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS
, INT
Tipo restituito
FLOAT
Esempi di codice
Esempio 1
L'esempio seguente recupera un elemento all'indice 1 da un array di numeri in virgola mobile.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 1) // 2.1
Esempio 2
L'esempio seguente recupera un elemento all'indice -1 da un array di numeri in virgola mobile.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 0-1) // 4.6
Esempio 3
L'esempio seguente recupera un elemento per un indice maggiore della dimensione dell'array.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 6) // 0.0
Esempio 4
L'esempio seguente recupera un elemento da un array vuoto.
arrays.index_to_float([], 0) // 0.0
Esempio 5
L'esempio seguente recupera un elemento all'indice 1 da un array di stringhe.
arrays.index_to_float(["1.2", "3.3", "2.4"], 1) // 3.3
Esempio 6
L'esempio seguente recupera un elemento all'indice 2 da un array di numeri interi.
arrays.index_to_float([1, 3, 2], 2) // 2.0
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-29 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-07-29 UTC."],[[["\u003cp\u003e\u003ccode\u003earrays.index_to_float\u003c/code\u003e retrieves an element from an array at a specified index and returns it as a float.\u003c/p\u003e\n"],["\u003cp\u003eThe function supports positive and negative indexing, where negative indices count backward from the end of the array.\u003c/p\u003e\n"],["\u003cp\u003eIt can handle arrays of strings, integers, or floats, and converts the element at the index to a float.\u003c/p\u003e\n"],["\u003cp\u003eIf the index is out of bounds or the array is empty, \u003ccode\u003earrays.index_to_float\u003c/code\u003e returns 0.0.\u003c/p\u003e\n"],["\u003cp\u003eThe function is available in both Rules and Search functionalities.\u003c/p\u003e\n"]]],[],null,["### arrays.index_to_float\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n arrays.index_to_float(array, index)\n\n#### Description\n\nReturns the element at the given index of an array. The element at that index is returned as a float.\n\nThe index is an integer value which represents the position of an element in the array.\nBy default, the first element of an array has an index of 0, and the last element has an index of n-1, where n is the size of the array.\nNegative indexing allows accessing array elements relative to the end of the array. For example, an index of -1 refers to the last element in the array and an index of -2 refers to the second to last element in the array.\n\n#### Param data types\n\n`ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS`, `INT`\n\n#### Return type\n\n`FLOAT`\n\n#### Code samples\n\n##### Example 1\n\nThe following example fetches an element at index 1 from an array of floats. \n\n arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 1) // 2.1\n\n##### Example 2\n\nThe following example fetches an element at index -1 from an array of floats. \n\n arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 0-1) // 4.6\n\n##### Example 3\n\nThe following example fetches an element for an index greater than the size of the array. \n\n arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 6) // 0.0\n\n##### Example 4\n\nThe following example fetches an element from an empty array. \n\n arrays.index_to_float([], 0) // 0.0\n\n##### Example 5\n\nThe following example fetches an element at index 1 from a string array. \n\n arrays.index_to_float([\"1.2\", \"3.3\", \"2.4\"], 1) // 3.3\n\n##### Example 6\n\nThe following example fetches an element at index 2 from an array of integers. \n\n arrays.index_to_float([1, 3, 2], 2) // 2.0"]]