Algorithm to get changes between two arrays

后端 未结 8 1460
难免孤独
难免孤独 2021-02-04 05:43

I needed to create an algorithm which will (efficiently) take an old array and a new array and give me back the changes between the two (which items added, which removed). It ha

8条回答
  •  时光取名叫无心
    2021-02-04 06:23

    There is no undefined constant. You should check the type of the variable instead:

    if (typeof o === 'undefined') o = [];
    

    Edit:

    As Tim Down showed, the property is actually defined in the standard, but as the standard doesn't define it to be constant, it's unreliable and should not be used.

提交回复
热议问题