Javascript 保存值而不进行更改

Javascript 保存值而不进行更改,javascript,reactjs,react-native,Javascript,Reactjs,React Native,我有一个持续发送值的设备,直到它停止 我将这些值保存在数组中 deviceMonitoring( device2 ){ //there I populate this.arrayTimestamp and then copy the first value. this.arrayElement = this.arrayTimestamp[0]; } 在其他函数中,我检查arrayTimestamp的大小,当它大于某个大小时,我执行某个操作: check(){ that.timeout = s

我有一个持续发送值的设备,直到它停止

我将这些值保存在数组中

deviceMonitoring( device2 ){
//there I populate this.arrayTimestamp and then copy the first value.
this.arrayElement = this.arrayTimestamp[0];
}
在其他函数中,我检查
arrayTimestamp
的大小,当它大于某个大小时,我执行某个操作:

check(){
 that.timeout = setInterval(function() {
  if( (that.arrayTimestamp.length > 100 ){
   that.arrayTimestampCopy = that.arrayTimestamp.splice( 0, 100 )}
   DBwrite.write({
      arrayDivide: this.arrayTimestampCopy
      firstElement: this.arrayElement
   })
   }
  }, 1000);
 } 
我想要实现的是
this.arrayElement
值始终保持不变。另一方面,当满足if条件,然后发生拼接时,
this.arrayElement
值会改变


我如何做???

不使用
拼接
您可以使用
切片
,因为切片不会修改原始数组

   that.arrayTimestampCopy = that.arrayTimestamp.slice( 0, 100)}

slice的文档在这里:

好的,我会试试,但是在其他100个元素之后,arrayTimestamp的大小将是200?