Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
arrays.index_to_float
arrays.index_to_float(array, index)
Description
Renvoie l'élément à l'index donné d'un tableau. L'élément à cet index est renvoyé sous forme de float.
L'index est une valeur entière qui représente la position d'un élément dans le tableau.
Par défaut, le premier élément d'un tableau a un index de 0 et le dernier élément a un index de n-1, où n est la taille du tableau.
L'indexation négative permet d'accéder aux éléments de tableau par rapport à la fin du tableau. Par exemple, un index de -1 fait référence au dernier élément du tableau et un index de -2 fait référence à l'avant-dernier élément du tableau.
Types de données des paramètres
ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS
, INT
Type renvoyé
FLOAT
Exemples de code
Exemple 1
L'exemple suivant récupère un élément à l'index 1 à partir d'un tableau de valeurs float.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 1) // 2.1
Exemple 2
L'exemple suivant récupère un élément à l'index -1 à partir d'un tableau de valeurs float.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 0-1) // 4.6
Exemple 3
L'exemple suivant récupère un élément pour un index supérieur à la taille du tableau.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 6) // 0.0
Exemple 4
L'exemple suivant récupère un élément à partir d'un tableau vide.
arrays.index_to_float([], 0) // 0.0
Exemple 5
L'exemple suivant récupère un élément à l'index 1 d'un tableau de chaînes.
arrays.index_to_float(["1.2", "3.3", "2.4"], 1) // 3.3
Exemple 6
L'exemple suivant récupère un élément à l'index 2 d'un tableau d'entiers.
arrays.index_to_float([1, 3, 2], 2) // 2.0
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/07/29 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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"]]