Hello @tarena,
The x refers to the element in the array, and the index refers to the element’s index in the array.
You can name these parameters differently.
e.g.
x = 'zero'
index = 0
x = 'one'
index = 1
x = 'two'
index = 2
The first callback function sets the keys of the object:
(x, index) => index
By this callback function, the keys are set to the corresponding index of the element in the array.
{
"0":
"1":
"2":
}
The second callback function (optional) sets the values of the object:
x => x.contains('two')
By the above callback function, the elements from the array are evaluated using contains(‘two’) String function and the value is set accordingly.
{
"0":false
"1":false
"2":true
}
Let me know if this makes things more understandable.
BR,
Aleksandar.