快照键不能与值findindex一起使用? [英] Snapshot key not working with value findindex?
本文介绍了快照键不能与值findindex一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何根据快照键来使findIndex工作?它不适用于变量,但实际上适用于手动字符串吗?!
How to make work findIndex depending of a snapshotkey ?it's not working with the variable but actually work with a manual string ?!
this.state.data = Object {
"date_add": 1574177488383,
"date_upd": 1574178141010,
"question": "1",
"key": "123455566",
}
ref.on('child_changed', snapshot => {
var key = snapshot.key
console.log('the key', key) // return 123455566
})
实际上不能这样工作:
var foundIndex = this.state.data.findIndex(x => x.key == key);
但要像这样
var foundIndex = this.state.data.findIndex(x => x.key == '123455566');
推荐答案
您应使用:
var foundIndex = this.state.data.findIndex(x => x.key == x.key);
我不确定要获取什么,但是使用 findindex
来获取值的索引.
Im not sure what you are trying to get but, you usefindindex
to get the index of a value.
您可以在此处看到多个示例:
You can see multiple examples here:
还有文档:
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex
这篇关于快照键不能与值findindex一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文