The _.assign method is the equivalent of the spread operator from ES6. It’s pretty easy to understand, it assigns properties of one or many objects to a source object.
Learn Lodash JS at Lodash JS Tutorial with Examples.
Lodash _.assign Method Example
<!DOCTYPE html> <html> <head> <title>Lodash Tutorial</title> <script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script> <script type="text/javascript"> var foo = { a: "a property" }; var bar = { b: 4, c: "an other property" } var result = _.assign({ a: "an old property" }, foo, bar); console.log(JSON.stringify(result)); </script> </head> <body></body> </html>
Output:
{"a":"a property","b":4,"c":"an other property"}
Comments
Post a Comment