Search code examples
iosarraysswiftenumerate

How do I compare two array Objects - Swift 4


I have 2 Array of type [Any] - objects of dictionaries
And other array contains other set of objects [Any] (2nd array objects are contains in first array)

I need to find the index of the first array of second array elements

eg: -

let firstArray = [["key1":6],["key2":8],["key3":64],["key4":68],["key5":26],["key6":76]]

let secondArray = [["key3":64],["key6":68]]

How can I find the firstArray index of secondArray elements


Solution

  • let index = firstArray.index{$0 == secondArray[0]};
    print("this value ", index);
    

    will print optional(2) , it is basically 2