1. /**
  2. * Searches for content within date values in an array of objects.
  3. * Primarily for development purposes.
  4. * @param {Array<Object>} data An array of objects, each containing a 'date' property.
  5. * @param {string} searchTerm The term to search for within the date values.
  6. * @returns {Array<Object>} An array of objects containing the search term within the date.
  7. */
  8. function searchDates(data, searchTerm) {
  9. if (!Array.isArray(data)) {
  10. console.error("Input data must be an array.");
  11. return []; // Return empty array if input is invalid
  12. }
  13. if (typeof searchTerm !== 'string') {
  14. console.error("Search term must be a string.");
  15. return [];
  16. }
  17. const results = [];
  18. for (const item of data) {
  19. if (item && typeof item.date === 'string') { //Check if date exists and is a string
  20. if (item.date.toLowerCase().includes(searchTerm.toLowerCase())) {
  21. results.push(item); // Add the object to results if the search term is found
  22. }
  23. }
  24. }
  25. return results;
  26. }
  27. //Example Usage (for testing)
  28. //const data = [
  29. // { id: 1, date: "2023-10-26" },
  30. // { id: 2, date: "Another date string" },
  31. // { id: 3, date: "2024-01-15" },
  32. // { id: 4, date: "This date has the word date" }
  33. //];
  34. //
  35. //const searchTerm = "date";
  36. //const foundItems = searchDates(data, searchTerm);
  37. //console.log(foundItems);

Add your comment