how to use the toplainobject function from lodash in javascript

To use toPlainObject function from lodash:

  1. Install lodash by running npm install lodash in your project directory or by including it via script tag in your html file.
  2. Import the toPlainObject function from lodash in your javascript code:
index.tsx
const { toPlainObject } = require('lodash');
45 chars
2 lines

or

index.tsx
import { toPlainObject } from 'lodash';
40 chars
2 lines
  1. Call the toPlainObject function on the object that you want to convert:
index.tsx
const myObj = {
  name: 'John',
  age: 30,
  hobbies: ['reading', 'writing', 'swimming']
};

const plainObj = toPlainObject(myObj);

console.log(plainObj);
// Output: { name: 'John', age: 30, hobbies: [ 'reading', 'writing', 'swimming' ] }
240 chars
11 lines

Note that toPlainObject creates a plain object with only own enumerable string keyed properties of an object.

gistlibby LogSnag