Skip to content Skip to sidebar Skip to footer

Snapshot Key Not Working With Value 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': 1

Solution 1:

var key = "123456";
var data = [{"key":"123456"},{"key": "123"},{"key":  "12"}, {"key":"1"}]
var foundIndex = data.findIndex(x => x.key == key);
console.log(foundIndex); //0var ind = data.findIndex(x => x.key == '12'); 
console.log(ind); //2

Solution 2:

You should use:

var foundIndex = this.state.data.findIndex(x => x.key == x.key);

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:

Get the index of the object inside an array, matching a condition

Find index of object in javascript by a value

Also the docs:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex

Post a Comment for "Snapshot Key Not Working With Value Findindex?"