You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| arrayToSearch | Yes | array | The array to use for finding the index of the searched item. |
460
+
| itemToFind | Yes | int, string, array, or object | The item to find in the array. |
461
+
462
+
### Return value
463
+
464
+
An integer representing the last index of the item in the array. The index is zero-based. If the item isn't found, -1 is returned.
465
+
466
+
### Examples
467
+
468
+
The following example shows how to use the indexOf and lastIndexOf functions:
469
+
470
+
```bicep
471
+
var names = [
472
+
'one'
473
+
'two'
474
+
'three'
475
+
]
476
+
477
+
var numbers = [
478
+
4
479
+
5
480
+
6
481
+
]
482
+
483
+
var collection = [
484
+
names
485
+
numbers
486
+
]
487
+
488
+
var duplicates = [
489
+
1
490
+
2
491
+
3
492
+
1
493
+
]
494
+
495
+
output index1 int = lastIndexOf(names, 'two')
496
+
output index2 int = indexOf(names, 'one')
497
+
output notFoundIndex1 int = lastIndexOf(names, 'Three')
498
+
499
+
output index3 int = lastIndexOf(numbers, 4)
500
+
output index4 int = indexOf(numbers, 6)
501
+
output notFoundIndex2 int = lastIndexOf(numbers, '5')
502
+
503
+
output index5 int = indexOf(collection, numbers)
504
+
505
+
output index6 int = indexOf(duplicates, 1)
506
+
output index7 int = lastIndexOf(duplicates, 1)
507
+
```
508
+
509
+
The output from the preceding example is:
510
+
511
+
| Name | Type | Value |
512
+
| ---- | ---- | ----- |
513
+
| index1 |int | 1 |
514
+
| index2 | int | 0 |
515
+
| index3 | int | 0 |
516
+
| index4 | int | 2 |
517
+
| index5 | int | 1 |
518
+
| index6 | int | 0 |
519
+
| index7 | int | 3 |
520
+
| notFoundIndex1 | int | -1 |
521
+
| notFoundIndex2 | int | -1 |
522
+
371
523
## length
372
524
373
525
`length(arg1)`
@@ -652,7 +804,7 @@ An array or object.
652
804
653
805
The union function uses the sequence of the parameters to determine the order and values of the result.
654
806
655
-
For arrays, the function iterates through each element in the first parameter and adds it to the result if it isn't already present. Then, it repeats the process for the second parameter and any additional parameters. If a value is already present, it's earlier placement in the array is preserved.
807
+
For arrays, the function iterates through each element in the first parameter and adds it to the result if it isn't already present. Then, it repeats the process for the second parameter and any more parameters. If a value is already present, its earlier placement in the array is preserved.
656
808
657
809
For objects, property names and values from the first parameter are added to the result. For later parameters, any new names are added to the result. If a later parameter has a property with the same name, that value overwrites the existing value. The order of the properties isn't guaranteed.
0 commit comments