Organízate con las colecciones
Guarda y clasifica el contenido según tus preferencias.
arrays.index_to_float
arrays.index_to_float(array, index)
Descripción
Devuelve el elemento situado en el índice indicado de una matriz. El elemento de ese índice se devuelve como un número de coma flotante.
El índice es un valor entero que representa la posición de un elemento en la matriz.
De forma predeterminada, el primer elemento de una matriz tiene el índice 0 y el último elemento tiene el índice n-1, donde n es el tamaño de la matriz.
La indexación negativa permite acceder a los elementos de una matriz en relación con el final de la matriz. Por ejemplo, el índice -1 hace referencia al último elemento de la matriz y el índice -2 hace referencia al penúltimo elemento de la matriz.
Tipos de datos de parámetros
ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS
, INT
Tipo de devolución
FLOAT
Códigos de ejemplo
Ejemplo 1
En el siguiente ejemplo se obtiene un elemento en el índice 1 de una matriz de números de coma flotante.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 1) // 2.1
Ejemplo 2
En el siguiente ejemplo se obtiene un elemento en el índice -1 de una matriz de números de coma flotante.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 0-1) // 4.6
Ejemplo 3
En el siguiente ejemplo se obtiene un elemento con un índice mayor que el tamaño de la matriz.
arrays.index_to_float([1.2, 2.1, 3.5, 4.6], 6) // 0.0
Ejemplo 4
En el siguiente ejemplo se obtiene un elemento de una matriz vacía.
arrays.index_to_float([], 0) // 0.0
Ejemplo 5
En el siguiente ejemplo se obtiene un elemento en el índice 1 de una matriz de cadenas.
arrays.index_to_float(["1.2", "3.3", "2.4"], 1) // 3.3
Ejemplo 6
En el siguiente ejemplo se obtiene un elemento en el índice 2 de una matriz de números enteros.
arrays.index_to_float([1, 3, 2], 2) // 2.0
A menos que se indique lo contrario, el contenido de esta página está sujeto a la licencia Reconocimiento 4.0 de Creative Commons y las muestras de código están sujetas a la licencia Apache 2.0. Para obtener más información, consulta las políticas del sitio web de Google Developers. Java es una marca registrada de Oracle o sus afiliados.
Última actualización: 2025-08-20 (UTC).
[[["Es fácil de entender","easyToUnderstand","thumb-up"],["Me ofreció una solución al problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Es difícil de entender","hardToUnderstand","thumb-down"],["La información o el código de muestra no son correctos","incorrectInformationOrSampleCode","thumb-down"],["Me faltan las muestras o la información que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-20 (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"]]