Open In App

Lodash _.create() Method

Last Updated : 27 Oct, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash _.create() method creates an object that inherits from the prototype object. If a properties object is given, its own enumerable string keyed properties are assigned to the created object.

Syntax:

_.create( proto_obj, property_object);

Parameters:

  • proto_obj: This is the object to inherit from.
  • property_object: These are the properties to assign to the object.

Return Value:

This method returns a new object.

Example 1: In this example, we are creating an object having a prototype of Geeks by the use of the lodash _.create() method.

javascript




// Defining Lodash variable
const _ = require('lodash');
 
function Geeks() {
  return true;
}
  
let GFG = _.create(Geeks.prototype, {
  'GeeksforGeeks': "Computer Science Portal"
});
 
console.log(GFG);


Output:

Geeks { GeeksforGeeks: 'Computer Science Portal' }

Example 2: In this example, we are creating an object having a prototype of protoFunc by the use of the lodash _.create() method.

javascript




// Defining Lodash variable
const _ = require('lodash');
 
function protoFunc() {
    return 'Geek';
}
 
let GFG = _.create(protoFunc.prototype, {
    'a': 'b'
});
 
console.log(GFG);


Output:

protoFunc { a: 'b' }

Note: This will not work in normal JavaScript because it requires the lodash library to be installed and can be installed using the following command:

npm install lodash

Previous Article
Next Article

Similar Reads

Lodash _.method() Method
Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method. Syntax: _.method(path, args);Parameters: path: This is the path to invoke.args: These are the arguments to invoke the method with.Return Value: This method returns the new invoker function.
1 min read
How to Create a Shallow Clone of a Value using Lodash ?
Shallow copy is the process of duplicating an object or array at the top level without copying nested objects or arrays. Below are the possible approaches to creating a shallow clone of a value using Lodash. Table of Content Using clone() functionUsing assign() functionRun the below command before running the code in your local system: npm i lodash
2 min read
How do we Create a Deep Clone of a Value using Lodash?
Lodash provides the _.cloneDeep() method to create a deep copy of a value, recursively cloning nested objects and arrays. This method ensures that the newly created object has the same value as the original but they are distinct objects in memory. Syntax_.cloneDeep(originalObj)Return Value:This method returns the deep-cloned value. Run the below co
2 min read
Lodash _.flattenDeep() and _.flattenDepth() Method
Lodash _.flattenDeep() Method The _.flattenDeep() method is used to completely flatten nested arrays. It does this recursively. Syntax: _.flattenDeep( array ) Parameters: This method accepts single parameter as mentioned above and described below: array: This parameter holds the array that to be flatten. Return Value: This method returns the new fl
2 min read
Lodash _.dropWhile() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers etc. The Loadsh.dropWhile() method is used to return the slice of the given array. This takes a predicate function that iterate through each element of the array and if the function returns false, it returned the sli
2 min read
Lodash _.stubFalse() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.stubFalse() method is used to always return a false value. The basic difference between using a normal false value and using the _.stubFalse() method is that lambda functions create a new different functi
1 min read
Lodash _.pullAllBy() Method
The _.pullAllBy() method is used to remove the values from the original array by iterating over each element in the array by using the Iteratee function. It is almost the same as _.pullAll() function. Syntax: _.pullAllBy(array, values, [iteratee=_.identity]) Parameters: This method accepts two parameters as mentioned above and described below: arra
2 min read
Lodash _.sortedLastIndexOf() Method
The _.sortedLastIndexOf method is used to return the highest index of the array where an element can be inserted and maintain its sorted order. Also this method is like _.lastIndexOf except that it performs a binary search on a sorted array.Syntax: _.sortedLastIndexOf(array, value) Parameters: This method accepts two parameters as mentioned above a
1 min read
Lodash _.isSymbol() Method
The _.isSymbol() method is used to find whether the given value is a symbol object or not. It returns True if the given value is a symbol object. Otherwise, it returns false. Syntax: _.isSymbol(value) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter holds the value to check. Return Val
1 min read
Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.toArray() method is used to convert the given value to an array. Syntax: _.toArray( value ) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter
1 min read