简体   繁体   English

将数据推送到对象/数组以供以后比较

[英]Pushing data to object/array for later comparison

I'm trying to store strings in a object/array for later comparison .我正在尝试将字符串存储对象/数组中以供以后比较 I have no idea if my approach is correct.我不知道我的方法是否正确。

The idea: I'll be using the data to compare if there's been changes in the HTML where the strings are from.想法:我将使用数据来比较字符串来自的 HTML 是否发生了变化。 If there are changes the script is gonna send a notification with information on what changes there is.如果有更改,脚本将发送通知,其中包含有关更改的信息。

So I have a function that needs to push data into either an object or an array.所以我有一个函数需要将数据推送到对象或数组中。 I need to store the data for later use, where I need to compare if there's any changes.我需要存储数据以备后用,我需要在那里比较是否有任何更改。 It's specifically a scheme of classes.它特别是一个类的方案。

An example of what the object/array is gonna look after the data is injected:注入数据后对象/数组将要处理的示例:

    obj = 
    {
      "mon": { 
              0:{date:date, info:info, class:class}
              1:{date:date, info:info, class:class}
              2:{date:date, info:info, class:class}
             },
      "tue": {...},
      "...":
    }

And so on... So the object/array is gonna contain data for every class, for every day.等等......所以对象/数组将包含每个类的数据,每天。 I need to be able to compare the stored obj.mon.0 with the new obj.mon.0, as an example.例如,我需要能够将存储的 obj.mon.0 与新的 obj.mon.0 进行比较。

So my question is:所以我的问题是:
What's the best approach, in an object as above, or in a array?在上述对象或数组中,最好的方法是什么?
How do I go about storing information in the object/array for every class, on every day?我如何每天在每个类的对象/数组中存储信息?
And is this even the easiest approach for this context?对于这种情况,这是否是最简单的方法?



Thank you for your time.感谢您的时间。

Array is probably the best to choose here. Array 可能是这里最好的选择。

and you can keep the date, info and class as object.并且您可以将日期、信息和类作为对象。

Please share your suggestions too.也请分享您的建议。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM