Open In App

# Check if a specific index of an array contains a value in Julia – isassigned() Method

The `isassigned()` is an inbuilt function in julia which is used to test whether the given index contains a value in the specified array or not.

Syntax: isassigned(array, i)

Parameters:

• array: Specified array
• i: Specified index value

Returns: It returns true if the specified index value is present in the array else false.

Example 1:

 `# Julia program to illustrate ``# the use of Array isassigned() method``  ` `# test whether the given index value 3 is``# present in the 1D array A.``A ``=` `[``5``, ``10``, ``15``, ``20``]``println(isassigned(A, ``3``))``  ` `# test whether the given index value 5 is``# present in the 2D array B of size 2 * 2``B ``=` `[``5` `10``; ``15` `20``]``println(isassigned(B, ``5``))``  ` `# test whether the given index value 9 is``# present in the 3D array C of size 2 * 2*2``C ``=` `cat([``1` `2``; ``3` `4``], [``5` `6``; ``7` `8``], ``        ``[``9` `10``; ``11` `12``], dims ``=` `3``)``println(isassigned(C, ``9``))`

Output:

Example 2:

 `# Julia program to illustrate ``# the use of Array isassigned() method``   ` `# test whether the given index value 3 is``# present in the 1D array A.``A ``=` `[``1``, ``2``, ``3``];``println(isassigned(A, ``10``))``   ` `# test whether the given index value 5 is``# present in the 2D array B of size 3 * 2``B ``=` `[``5` `10``; ``15` `20``; ``25` `30``];``println(isassigned(B, ``25``))``   ` `# test whether the given index value 9 is``# present in the 3D array C of size 2 * 2*4``C ``=` `cat([``1` `2``; ``3` `4``], [``5` `6``; ``7` `8``], ``        ``[``9` `10``; ``11` `12``], [``13` `14``; ``15` `16``], dims ``=` `3``);``println(isassigned(C, ``9``))`

Output: