Javascript 创建要插入到数组中的时间计数器
我在创建添加到数组的时间(以毫秒为单位)时遇到问题 我有一个从两个外部设备读取数据的应用程序。所以我需要插入一个关于读取这些数据的时间 我有这样一个函数:Javascript 创建要插入到数组中的时间计数器,javascript,react-native,Javascript,React Native,我在创建添加到数组的时间(以毫秒为单位)时遇到问题 我有一个从两个外部设备读取数据的应用程序。所以我需要插入一个关于读取这些数据的时间 我有这样一个函数: async setupNotifications1(device) { const service = this.serviceGeneral(); device.monitorCharacteristicForService( service, this.AccGyrMg, (error,
async setupNotifications1(device) {
const service = this.serviceGeneral();
device.monitorCharacteristicForService(
service,
this.AccGyrMg,
(error, characteristic) => {
if (error) {
this.error(error.message);
return;
}
const buf = Buffer.from(characteristic.value, "base64");
const [...acc_dx] = [2, 4, 6].map(index => buf.readInt16LE(index));
this.setState(state => ({
acc_dx,
array_acc_dx: [
...state.array_acc_dx,
[acc_dx],
]
}));
/* pressure */
device.monitorCharacteristicForService(
service,
this.Pressure,
(error, characteristic) => {
if (error) {
this.error(error.message);
return;
}
const buf = Buffer.from(characteristic.value, "base64");
const [...pressure_dx] = [0, 2, 4, 6, 8].map(index => buf.readUInt16LE(index));
this.setState(state => ({
pressure_dx,
array_pressure_dx: [
...state.array_pressure_dx,
[pressure_dx]
]
}));
}
);
如何创建一个时间来连接[…acc_dx]和[pressure_dx]?谢谢您可以考虑使用setTimeout()来完成此操作 因此,在您的情况下,您可以有如下内容:
setTimeout(() => {
addToArray();
}, 300);
如何在数组中插入?我应该获得类似[时间,[加速度]]