In order to create a clone of a Javascript object while excluding a set of attributes we can use the following formula:
const {prop1, prop2, propN, ...newObj} = ingredients
Let's say we have the the following Javascript object:
const ingredients = {
apples: 'š',
chicken: 'š',
bread: 'š„',
broccoli: 'š„¦',
milk: 'š„'
}
If we want to create a new object noMeat, while excluding the chicken property from the initial object we can do:
const {chicken, ...noMeat} = ingredients

And it will work also with multiple excluded properties:
const {milk, chicken, ...vegetarian} = ingredients
Using the spread operator and the destructing statement is a shorthand for writing somethig like this:
const vegetarian = Object.assign({}, ingredients);
delete vegetarian.milk;
delete vegetarian.chicken;
The full code is here and the live example is on GitHub pages.
š Build a full trivia game app with LangChain
Learn by doing with this FREE ebook! This 35-page guide walks you through every step of building your first fully functional AI-powered app using JavaScript and LangChain.js
š Build a full trivia game app with LangChain
Learn by doing with this FREE ebook! This 35-page guide walks you through every step of building your first fully functional AI-powered app using JavaScript and LangChain.js