darekf77 / lodash-walk-object

Iterate all properties of object or array

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WALK ALL PROPERTIES DEEP IN OBJECT

This library let you go deep through all properties in your javascript object with nice possibility to change theirs values without confusion.

WALK OBJECT

walk.Object( myJSObject, iteratorFunction )

walk.ObjectBy( myObjectPropert, contextObject , iteratorFunction )

There are both similar... the difference is that, with second function you main object is also included in iteration and can be changed.

Example

import { walk } from 'lodash-walk-object'

let = yourJSObject = {
  isGood: true,
  arr = [ 
    {  insideObjectValue: 1 } 
    {  insideObjectValue: 1 } 
  ],
  testObject: {}
}

walk.Object(yourJSObject, (value, lodashPath, changeValue) => {
  if(lodashPath === 'arr[0].insideObjectValue') {
    changeValue(2)
  }
} )

console.log(yourJSObject)

// RESULT

/*
{
  isGood: true,
  arr = [ 
    {  insideObjectValue: 2 } 
    {  insideObjectValue: 1 } 
  ],
  testObject: {}
}
*/

About

Iterate all properties of object or array


Languages

Language:TypeScript 80.5%Language:HTML 16.7%Language:JavaScript 2.8%