Snippets Collections
// Ensure object exists
currentAccount ||= {};

// Ensure movementsDates exists if currentAccount already has it defined
currentAccount.movementsDates ||= [];

// Add the current date in ISO format to the movementsDates array
currentAccount.movementsDates.push(new Date().toISOString());

console.log(currentAccount.movementsDates);
const todos = [
  {
    id: 1,
    task: "buy milk",
  },
  {
    id: 2,
    task: "go to gym",
  },
  {
    id: 3,
    task: "clean apartment",
  },
];

const existingToDos = []; // create new array
todos.forEach((item) => todos.length && existingToDos.push(item)); // loop over and push into new arrat if the length is more than 0;

console.log("existing =>", existingToDos);





// check todos that have a task that has a string containing 'buy'
const containsBuy = [];
const reguarExp = new RegExp("buy");
todos.filter((item) => item.task.match(reguarExp) && containsBuy.push(item));
console.log("containsBuy => ", containsBuy);
star

Mon Jul 08 2024 22:54:44 GMT+0000 (Coordinated Universal Time)

#checking #object
star

Sun Apr 28 2024 00:11:22 GMT+0000 (Coordinated Universal Time)

#objects #checking #array #regex

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension