arrayContainsObject.js 746 B

123456789101112131415161718192021222324252627282930
  1. /**
  2. * Copyright (c) 2015-present, Parse, LLC.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. * @flow
  10. */
  11. import ParseObject from './ParseObject';
  12. export default function arrayContainsObject(array
  13. /*: Array<any>*/
  14. , object
  15. /*: ParseObject*/
  16. )
  17. /*: boolean*/
  18. {
  19. if (array.indexOf(object) > -1) {
  20. return true;
  21. }
  22. for (let i = 0; i < array.length; i++) {
  23. if (array[i] instanceof ParseObject && array[i].className === object.className && array[i]._getId() === object._getId()) {
  24. return true;
  25. }
  26. }
  27. return false;
  28. }