Finding what is common to two arrays

后端 未结 2 1415
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 14:31

Is there a way to compare two arrays and show what is common to both of them?

array1 = [\"pig\", \"dog\", \"cat\"]
array2 = [\"dog\", \"cat\", \"pig\", \"hor         


        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-23 14:53

    You can intersect the arrays using &:

    array1 & array2
    

    This will return ["pig", "dog", "cat"].

提交回复
热议问题