viruschidai / diff-json

A javascript object diff tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't produce diff if array elements order is changed

nicholaswmin opened this issue · comments

I would expect that a different order of items in an array would also produce a diff. It doesn't.

Here's an example:

const changesets = require('diff-json')

const newObj = {
  children: [
    // kid2 is first here
    {name: 'kid2', age: 2},
    {name: 'kid1', age: 1}
  ]}

const oldObj = {
  // kid1 is first here
  children: [
    {name: 'kid1', age: 1},
    {name: 'kid2', age: 2}
  ]}

const diffs = changesets.diff(oldObj, newObj, {children: 'name'})
console.log(JSON.stringify(diffs, null, 2))

@nicholaswmin
if you don't pass {children: 'name'}, it will show you the diff of the array

const diffs = changesets.diff(oldObj, newObj)