Skip to content

Instantly share code, notes, and snippets.

@Gpzim98
Last active October 3, 2017 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gpzim98/5bf6b0946b30673bda44670470585ec3 to your computer and use it in GitHub Desktop.
Save Gpzim98/5bf6b0946b30673bda44670470585ec3 to your computer and use it in GitHub Desktop.
# 1 - Promisses
p.then(onFulfilled[, onRejected]);
p.then(function(value) {
// fulfillment
}, function(reason) {
// rejection
});
# 2 - Find an object in a array
let obj = arr.find((o, i) => {
if (o.name === 'string 1') return true;
});
# 3 - Replacing object in a array
let arr = [
{ name:"string 1", value:"this", other: "that" },
{ name:"string 2", value:"this", other: "that" }
];
let obj = arr.find((o, i) => {
if (o.name === 'string 1') {
arr[i] = { name: 'new string', value: 'this', other: 'that' };
return true; // stop searching
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment