从api响应中,我想要不使用forEach获取索引#include <SoftwareSerial.h>
#include <MemoryFree.h>
#include <MD5.h>
void setup() {
// initialize the digital pin as an output.
Serial.begin(115200);
Serial.println("Starting");
Serial1.begin(115200);
delay(200);
}
// the loop routine runs over and over again forever:
void loop() {
Serial1.println("AT");
delay(100);
Serial.println(Serial1.readString());
Serial.println("-----------");
unsigned char* hash=MD5::make_hash("hello world, this an example");
//generate the digest (hex encoding) of our hash
char *md5str = MD5::make_digest(hash, 16);
//print it on our serial monitor
Serial.println(md5str);
//Give the Memory back to the System if you run the md5 Hash generation in a loop
free(md5str);
Serial.println(freeMemory());
}
数组。我在下面找到了ES2016解决方案但是当我运行以下JavaScript时我得到了
EXCEPTION:response.findIndex不是函数
的JavaScript
results
响应
console.log( response.findIndex(x => x.results.id === 5 ) );
答案 0 :(得分:3)
findIndex
需要数组,但您的响应是一个对象。但是名为results
的属性是一个数组。
转换此
response.findIndex(x => x.results.id === 5 )
到这个
response.results.findIndex(x => x.id === 5 )