Skip to content

Instantly share code, notes, and snippets.

@robzhu
Created May 2, 2019 17:45
Show Gist options
  • Save robzhu/c0ceab7aff6f83e798cc85e7953fafa4 to your computer and use it in GitHub Desktop.
Save robzhu/c0ceab7aff6f83e798cc85e7953fafa4 to your computer and use it in GitHub Desktop.
async function removeFriendByValue(friendName: string) {
const Key = { id: "1234" };
// fetch the document
let result = await DynamoDB.get({
TableName,
Key
}).promise();
// find the index
const indexToRemove = result.Item.friends.indexOf(friendName);
if (indexToRemove === -1) {
// element not found
return;
}
// remove-by-index
await DynamoDB.update({
TableName,
Key,
UpdateExpression: `REMOVE friends[${indexToRemove}]`,
}).promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment