Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
arrays.index_to_int
arrays.index_to_int(array_of_inputs, index)
Deskripsi
Menampilkan nilai pada indeks tertentu dalam array sebagai bilangan bulat.
Indeks adalah nilai bilangan bulat yang mewakili posisi elemen dalam array.
Secara default, elemen pertama array memiliki indeks 0, dan elemen terakhir memiliki indeks n-1, dengan n adalah ukuran array.
Pengindeksan negatif memungkinkan akses ke elemen array relatif terhadap akhir array. Misalnya, indeks -1 merujuk ke elemen terakhir dalam array dan indeks -2 merujuk ke elemen kedua dari terakhir dalam array.
Jenis data parameter
ARRAY_STRINGS|ARRAY_INTS|ARRAY_FLOATS
, INT
Jenis hasil yang ditampilkan
INT
Contoh kode
Contoh 1
Panggilan fungsi ini menampilkan 0 saat nilai pada indeks adalah string non-numerik.
arrays.index_to_int(["str0", "str1", "str2"], 1) = 0
Contoh 2
Fungsi ini menampilkan elemen pada indeks -1.
arrays.index_to_int(["44", "11", "22", "33"], 0-1) = 33
Contoh 3
Menampilkan 0 untuk elemen di luar batas.
arrays.index_to_int(["44", "11", "22", "33"], 5) = 0
Contoh 4
Fungsi ini mengambil elemen dari array float pada indeks 1.
arrays.index_to_int([1.100000, 1.200000, 1.300000], 1) = 1
Contoh 5
Fungsi ini mengambil elemen dari array int pada indeks 0.
arrays.index_to_int([1, 2, 3], 0) = 1
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-29 UTC.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-29 UTC."],[[["\u003cp\u003e\u003ccode\u003earrays.index_to_int\u003c/code\u003e retrieves an element from an array at a specified index and returns it as an integer.\u003c/p\u003e\n"],["\u003cp\u003eThe function supports positive and negative indexing, with negative indices counting from the end of the array.\u003c/p\u003e\n"],["\u003cp\u003eIf the element at the specified index is a non-numeric string or the index is out of bounds, the function returns 0.\u003c/p\u003e\n"],["\u003cp\u003eThe function takes two parameters, the first being the array (that can consist of string, integers or float values), and the second the index (an integer).\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003earrays.index_to_int\u003c/code\u003e is supported in both Rules and Search.\u003c/p\u003e\n"]]],[],null,["### arrays.index_to_int\n\nSupported in: \n[Rules](/chronicle/docs/detection/default-rules) [Search](/chronicle/docs/investigation/udm-search) \n\n arrays.index_to_int(array_of_inputs, index)\n\n#### Description\n\nReturns the value at a given index in an array as an integer.\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`INT`\n\n#### Code samples\n\n##### Example 1\n\nThis function call returns 0 when the value at the index is a non-numeric string. \n\n arrays.index_to_int([\"str0\", \"str1\", \"str2\"], 1) = 0\n\n##### Example 2\n\nThis function returns the element at index -1. \n\n arrays.index_to_int([\"44\", \"11\", \"22\", \"33\"], 0-1) = 33\n\n##### Example 3\n\nReturns 0 for the out-of-bounds element. \n\n arrays.index_to_int([\"44\", \"11\", \"22\", \"33\"], 5) = 0\n\n##### Example 4\n\nThis function fetches the element from the float array at index 1. \n\n arrays.index_to_int([1.100000, 1.200000, 1.300000], 1) = 1\n\n##### Example 5\n\nThis function fetches the element from the int array at index 0. \n\n arrays.index_to_int([1, 2, 3], 0) = 1"]]